使用 if 语句编写一个程序,计算一个数字包含多少位:
我的代码:
#include <stdio.h>
int main (void)
{
int n;
printf ("Enter number :");
scanf ("%d",&n);
if ( n<=9)
printf ("Textnumber has one digit:");
if ( n <=99)
printf ("Textnumber has two digits:");
if (n<=999)
printf ("Textnumber has three digits:");
if (n <=9999)
printf ("Textnumber has four digits:");
return 0;
}
问题是当我运行它时,我输入了例如:223
我的屏幕上有结果:
Textnumber has three digitsTextnumberhasfourdigits...
我哪里错了?