/* C Program to Count Number of Digits in a Number using While Loop */
#include <stdio.h>
int main()
{
int Number, Reminder, Count=0;
printf("
Please Enter any number
");
scanf("%d", &Number);
while(Number > 0)
{
Number = Number / 10;
Count = Count + 1;
}
printf("
Number of Digits in a Given Number = %d", Count);
return 0;
}
digits = (number == 0) ? 1 : (log10(number) + 1);
//or
while (number > 0)
{
number /= 10;
digits++;
}
//see: https://ideone.com/P1h8Ne
#include <stdio.h>
int main(){
int num = 1024;
while(num != 0){
int digit = num % 10;
num = num / 10;
printf("%d
", digit);
}
return 0;
}
int numberOfDigits = 1 + log10(number) // stores number of digits in integer