#include
int main(void)
{
int number, digits;
digits = 0; /* This variable counts the digits. Initially it is 0. */
printf("This program counts the number of digits in an integer.\n");
printf("Enter a nonnegative integer: ");
scanf("%d", &number);
/* We have to execute the body of this loop at least once anyway, and
for this reason, do-while is more convenient here than a while-loop. */
do { /* start loop body */
number = number /10; /* note we do integer division here */
digits++; /* each time we increase the counter */
} /* end loop body */
while ( number > 0 ) ; /* evaluate termination condition */
/* Notice we have to write ";" after the while(condition) to show
this is the end of do-while loop statement */
printf("The number has %d digits.\n", digits);
return 0;
}