Arjun wants to count total number of digits of an Integer number (N). Help him to generate the program using do while loop.
#include <stdio.h>
int main()
{
int number;
int digits;
printf("Input a integer: ");
if(scanf("%d", &number) != 1)
{
printf("Bad input\n");
return 1;
}
if(number == 0)
{
digits = 1;
}
else
{
digits = 0;
while(number != 0)
{
digits++;
number /= 10;
}
}
printf("Total number of digits is %d\n", digits);
return 0;
}
Comments
Leave a comment