In: Computer Science
Write a program that calculates how many digits an integer value acquired via scanf() contains. A correctly functioning program should produce the following output, where the user entered the value 374:
Enter a number: 374
The number 374 has 3 digits
You may assume that the input integer has no more than four digits.
Use if statements to test the number. For example,
if the integer value entered by the user is between 0 and 9, it has
one digit. If the integer value is between 10 and 99, it has two
digits.
Rewrite the program without using if or switch statements. Instead use a do-while loop.
When implemented correctly, the user should be able to input any integer value (that will fit in a storage variable of type int) and its number of digits will be correctly determined without you needing to implement special logic for each possible quantity digits.
Hint:
The number of digits is very simply related to the number of
times the input integer value may be divided by
10.
As you didin't mentioned the programming language i did it in python
------------------------------------------------------------------------
a = int(input("Enter a number: ")) #enter the number you want to
know the digits
b = str(a) #convert the number to string
c = len(b) #find the length of the string
print("The number %d has %d digits"%(a,c)) #print the digits in the
number
-----------------------------------------------------------------------
------------------------------------------------------------------------
Kindly comment your queries if any,upvote if you like it. Thank You!!