读书人

求凌波仙子数bug死活找不到。

发布时间: 2013-01-22 10:23:54 作者: rapoo

求水仙花数,bug死活找不到。。。

#include<stdio.h>
#include<math.h>
int main()
{
int m,n,temp,a,b,c,i,num=0; //num判断是否出现过水仙花数
while(scanf("%d &d",&m,&n)!=EOF)
{
num=0;
if(m>n)
{
temp=m;
m=n;
n=temp;
}
while(m<=n)
{
a=(m/100);//取其百位数字
b=(m/10-10*a);//取其十位数字
c=(i%10);//取其个位数字
printf("%d,%d,%d",a,b,c);
getchar();
if( m==(pow(a,3)+pow(b,3)+pow(c,3)) )
{
printf("%d ",m);
num=1;
}
++m;
}
if(num==0)
printf("no");
printf("\n");
}
return 0;
}


printf("%d,%d,%d",a,b,c);这个怎么输出一直是错的
水仙花 math.h c
[解决办法]
scanf("%d &d",&m,&n)

a=(m/100);//取其百位数字
b=(m/10-10*a);//取其十位数字
c=(i%10);//取其个位数字

abc的计算是错的

# include <stdio.h>
# include <math.h>

int main()
{
int m, n, temp, a, b, c, num = 0;

printf("input m and n (100 ~ 999): ");
scanf("%d%d", &m, &n);

if (m > n)
{
temp = m;
m = n;
n = temp;
}

while (m <= n)
{
a = m / 100;
b = m / 10 % 10;
c = m % 10;
if (m == pow(a, 3) + pow(b, 3) + pow(c, 3))
{
printf("%d\n", m);
num++;
}
m++;
}

if (num)
printf("there are %d\n", num);
else
printf("no");

return 0;
}

读书人网 >C++

热点推荐