QUESTION DESCRIPTION :
C Program to Count number of digits in number without using mod operator
TEST CASE 1
INPUT
1234
OUTPUT
Number of Digits:4
TEST CASE 2
INPUT
874527
OUTPUT
Number of Digits:6
C Program to Count number of digits in number without using mod operator
TEST CASE 1
INPUT
1234
OUTPUT
Number of Digits:4
TEST CASE 2
INPUT
874527
OUTPUT
Number of Digits:6
EXPLANATION :
The problem requires you to count the number of digits in a number being input. The method used is to continuously divide the number by 10 , to reduce the digits by 1 and increase the counter
ALGORITHM :
- Take input from the user ( a )
- Take a while loop , with the condition , number > 0 ( a>0 )
- Divide the number by 10 and save it in the original variable ( a=a/10 )
- Increase the count by 1 ( i++ )
- Loop till the number becomes 0 ( loop condition is not satisfied )
- Print the counter ( i )
No comments:
Post a Comment