Write a function num_digits(n) that returns the number of digits in n ( a positive integer). Hint: to determine the number of digits in a number n, divide it by 10 repeatedly. when n reaches 0, the number of divisions indicates how many digits n originally had.
寫一個num_digits(n)函數 計算n有幾位數
#include <stdio.h>
int num_digits(int n)
{
/*INSERT YOUR CODE HERE*/
/*在這裡寫你的程式*/
/*END OF YOUR CODE*/
}
int main(void)
{
int n;
scanf("%d", &n);
printf("%d has %d digit(s)",n,num_digits(n));
return 0;
}
Please complete this program by only insert your code between those tags:
/*INSERT YOUR CODE HERE*/
/*END OF YOUR CODE*/
Example input
12347
Example output
12347 has 5 digit(s)
Remember: You may correct the cases, but your code always be revised!