输出所有的“水仙花数”。所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。例如,153是一水仙花数,因为153=1³+5³+3³。急急急!!!
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
int n=100;
while(n<=999)
{
a=n%10; b= n/10%10; c=n/100;
if(a*a*a +b*b*b+c*c*c ==n)
cout << n <<" ";
n++;
}
return 0;
}
#include <stdio.h>
int main()
{
int hun, ten, ind, n;
printf("result is:");
for( n=100; n<1000; n++ ) /*整数的取值范围*/
{
hun = n / 100;
ten = (n-hun*100) / 10;
ind = n % 10;
if(n == hun*hun*hun + ten*ten*ten + ind*ind*ind) /*各位上的立方和是否与原数n相等*/
printf("%d ", n);
}
printf("\n");
return 0;
}
#include <stdio.h>
#include <math.h>
int main(){
int j,k,l;
int i=100;
while (i<=999)
{
j=i%10,k=(i/10)%10,l=i/100;
if (i==pow(j,3)+pow(k,3)+pow(l,3)){
printf("%d\n",i);
}
++i;
}
}