首页 > 试题广场 >

确定一个数的位数

[问答题]

题目标题:

3.4 确定一个数的位数

题目描述:

编写程序用来确定一个数的位数。如:输入: 567 输出:The number 567 has 3 digits 假设输入的数最多不超过四位。

输入描述:

一个整数n

输出描述:

按指定格式输出这个数的位数。

样式输入:

567

样式输出:

The number 567 has 3 digits

#include <stdio.h>
main()
{
int n,x,digits=0;
scanf("%d",&n);
x=n;
do
{
x=x/10;
digits++;
}while(x);
printf("The number %d has %d digits",n,digits);

}

发表于 2017-05-15 00:15:46 回复(0)