急需那位好心人解决一下,为啥我的答案错误
题目来源:PTA
浙大版《C语言程序设计(第3版)》题目集
习题5-6 使用函数输出水仙花数 (20分)
#include <stdio.h>
int narcissistic( int number );
void PrintN( int m, int n );
int main()
{
int m, n;
scanf("%d %d", &m, &n);
if ( narcissistic(m) ) printf("%d is a narcissistic number\n", m);
PrintN(m, n);
if ( narcissistic(n) ) printf("%d is a narcissistic number\n", n);
return 0;
}
/* 你的代码将被嵌在这里 */
int narcissistic( int number )
{
int t;
int geweishu,shiweishu,baiweishu;
if(number<1000)
{
geweishu = number%10;
shiweishu = (number/10)%10;
baiweishu = number/100;
t= geweishu*geweishu*geweishu + shiweishu*shiweishu*shiweishu + baiweishu*baiweishu*baiweishu;
if(t==number)
{
t=1;
}
else{
t=0;
}
}
else{
t=0;
}
return t;
}
void PrintN( int m, int n )
{
for(int i=m+1;i<n;i++)
{
if(narcissistic(i)){
printf("%d\n",i);
}
}
}