判断一个十进制数是几位数

因为有0的存在,所以循环体部分至少要循环一次。

#include 
#include 

int bit_num(int n)
{
    int count = 0;
    do
    {
        n = n / 10;
        count++;
    }   while (n > 0);
    return count;
}
int main()
{
    int c = 0;
    int num = 0;
    int bit = 0;
    printf("请输入一个正整数:\n");
    scanf("%d",&num);
    c = bit_num(num);
    printf("bit is %d\n",bit_num(num));
    system("pause");
    return 0;
}

你可能感兴趣的:(c)