Search Your Query

Breaking

Sunday, July 7, 2019

Count The NUmber Of Digit In An Integer Number


Count the Number Of Digit In An Integer Number


Program Code:

#include<stdio.h>
int main()
{
int num,c=0;
printf("Enter the numnber\n");
scanf("%d",&num);
while(num>0)
{
num=num/10;
c++;
}
printf("The count number is-->%d\n",c);
return 0;
}

Hence, if enter number is greater than zero then , the statement will execute inside the while loop. As 121 is greater than zero then first num=num/10; will execute and num assigns 12 [the fraction part of the number will neglect cause of the variable type is integer] and then c++; will execute and c increament by 1 and the loop will continue until the condition is breaked.

Input:

121

Output:

The count number is-->3

No comments:

Post a Comment