目的:输入任意长度整数数字,求出所含数字位数
[tiger506@localhost C_C++]$ cat ./num_dig.c
#include<stdio.h>
int num_digit(int n)
{
int count = 0;
while(n != 0)
{
count++;
n = n / 10;
}
return count;
}
int main(void)
{
int n;
printf("Enter a number: ");
scanf("%d", &n);
printf("The digit of the number is : %d\n", num_digit(n));
return 0;
}
本文转自 tiger506 51CTO博客,原文链接:http://blog.51cto.com/tiger506/456848,如需转载请自行联系原作者