Homework3-3 - printf("Please enter a number...

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printf(&quot;Please enter a number between 1 and 9999\n&quot;); scanf(&quot;%d&quot;, &amp;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(&quot;\nThe number you entered has %d digits in it.&quot;, num_count); return (0); }...
View Full Document

Page1 / 2

Homework3-3 - printf(&amp;amp;quot;Please enter a number...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online