求大神解答,一个很简单的C语言问题,谢谢了。
程序如下:#include<stdio.h>voidmain(){longintnum,sum;printf("pleaseinputthenum:\n");scanf(...
程序如下:
#include <stdio.h>
void main()
{
long int num,sum;
printf("please input the num:\n");
scanf("%d",&num);
if(num/10000==0)
{if(num/1000==0)
{if(num/100==0)
{if(num/10==0)
{if(num/1==0)
printf("the num is 0\n");
else
printf("the num is one-digit num\n");
sum=num;
}
else
printf("the num is two-digit num\n");
sum=(num/10)+(num%10);
}
else
printf("the num is three-digit num\n");
sum=(num/100)+((num/10)%10)+(num%10);
}
else
printf("the num is four-digit num\n");
sum=(num/1000)+((num/100)%10)+((num/10)%10)+(num%10);
}
else
printf("the num is five-digit num\n");
sum=(num/10000)+((num/1000)%10)+((num/100)%10)+((num/10)%10)+(num%10);
printf("sum=%d",sum);
}
可是当输入99999时,sum=20,这是怎么回事啊?求解答啊
显示如下:
please input the num:
99999
the num is five-digit num
sum=20 展开
#include <stdio.h>
void main()
{
long int num,sum;
printf("please input the num:\n");
scanf("%d",&num);
if(num/10000==0)
{if(num/1000==0)
{if(num/100==0)
{if(num/10==0)
{if(num/1==0)
printf("the num is 0\n");
else
printf("the num is one-digit num\n");
sum=num;
}
else
printf("the num is two-digit num\n");
sum=(num/10)+(num%10);
}
else
printf("the num is three-digit num\n");
sum=(num/100)+((num/10)%10)+(num%10);
}
else
printf("the num is four-digit num\n");
sum=(num/1000)+((num/100)%10)+((num/10)%10)+(num%10);
}
else
printf("the num is five-digit num\n");
sum=(num/10000)+((num/1000)%10)+((num/100)%10)+((num/10)%10)+(num%10);
printf("sum=%d",sum);
}
可是当输入99999时,sum=20,这是怎么回事啊?求解答啊
显示如下:
please input the num:
99999
the num is five-digit num
sum=20 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询