{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Homework3-3

# Homework3-3 - printf"Please enter a number between 1...

This preview shows pages 1–2. Sign up to view the full content.

Homework #3 /* * Program Hw3_3 Digit calculator * Written by Justin Waters * Inputs: an integer up to 4 digits * Outputs: # of digits in the value entered * Description: the user enters a number and the program tells how many digits are in the number*/ #include <stdio.h> //printf, scanf defined #include <math.h> //math functions int main (void) { int user_num, a, b, c, d, e, f, g, num_count; /*variables used for digit count calculations*/ num_count = 0; //initialize variable //tells user what the program does printf("This program will tell you how many digits \nare in the number you are asked to enter.\n"); //gets a number from the user

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printf("Please enter a number between 1 and 9999\n"); scanf("%d", &user_num); //calculating # of digits a = user_num / 1000; if (a == 0) {num_count = num_count; } else { num_count++;} b = user_num - (a * 1000); c = b / 100; if (c == 0) {num_count = num_count; } else { num_count++;} d = b - (c * 100); e = d / 10; if (e == 0) {num_count = num_count; } else {num_count++;} f = d - (e *10); g = f / 1; if (g == 0) {num_count = num_count; } else {num_count++;} //tells user how many digits are in the value entered printf("\nThe number you entered has %d digits in it.", num_count); return (0); }...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

Homework3-3 - printf"Please enter a number between 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online