Write a C programs to find number of digits in a number.
int main() {
int value = 0, mod, digit = 0;
/* get the input value from the user */
printf("Enter your input value:");
scanf("%d", &value);
/* find the number of digits */
while (value > 0) {
mod = mod % 10;
digit++;
value = value / 10;
}
/* print the number of digits */
printf("No of digits in the given number is %d\n",
digit ? digit : 1);
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter your input value:12345
No of digits in the given number is 5
Enter your input value:12345
No of digits in the given number is 5
No comments:
Post a Comment