C语言 编写一个程序,输入一个正整数,求出它是几位数。

如题所述

/*功能:输入一个任意长度的正整数,求出它是几位数。*/
#include<stdio.h>
int main()
{
int number; int count = 0;//记录个数
scanf("%d", &number);
if (number == 0)
{

printf("number is %d\n",count+1);//0是一位数
} else
{

while (number != 0)
{
number = number / 10;
count++;
} printf("number is %d", count);
} return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2021-04-21
完整代码如下,仅供参考:

#include<stdio.h>
int main()
{
int n,count=0;
scanf("%d", &n);
if (n <= 0)
{
printf("必须输入");
return 1;
} else
{
while (n != 0)
{
n = n / 10;
count++;
}
printf("n是%d位数", count);
}

return 0;
}本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网