Problem: Program to count number of digits of a given number.
To count the digits do the following steps:
- Remove last digit of a number N by dividing it with 10.
- Increment the count by 1.
- Repeat steps 1 and 2 until the value of N becomes 0.
#include<stdio.h>
int main() {
int num, countDigits=0;
scanf("%d",&num);
while(num!=0){
num /= 10;
countDigits++;
}
printf("%d",countDigits);
return 0;
}
int main() {
int num, countDigits=0;
scanf("%d",&num);
while(num!=0){
num /= 10;
countDigits++;
}
printf("%d",countDigits);
return 0;
}