Write a program to read an integer number and find its number of digits (for exa
ID: 3620329 • Letter: W
Question
Write a program to read an integer number and find its number of digits (for example, 3459 has 4 digits and 125860 has 6 digits).The program should be designed in a way that the user could test as many numbers as desired without leaving the program. Use only long integer ( int or long int ) data type in this problem; however make sure that the program rejects any input outside the long integer data range(about -2,000,000,000 to +2,000,000,000).
The outputs of the program should be written to an output file having a format exactly like the following table.
VALUE ENTERED NUMBER OF DIGITS
1241 4
19 2
5684900 7
0 1
1267678901 10
-153 3
62000 5
Test the program for at least seven integer values between ± 2,000,000,000 and a number outside the long int data range . Remember to submit a copy of the program file and a copy of the output file.
Explanation / Answer
int num_digits; if (myNumber < 0) myNumber = -myNumber; while(myNumber > 0) { num_digits++; myNumber/=10; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.