求水仙花数,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;
}
# 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;
}