#include
#include
int main(){
int i=0;
int a,b,c;
int l1,l2,l3;
double temp;
for(i=100;i<=999;i++){
a=i/100 ;
b=(i/10)-10;
c=i-a*100-b*10;
l1=pow(a,3);l2=pow(b,3);l3=pow(c,3);
temp=l1+l2+l3;
if(temp==i){
printf("%d\n",i);
}
}
return 0;
}
取三个位数的方法错误;temp变量也是余的,应该为:
#include<stdio.h>
#include<math.h>
int main(){
int i=0;
int a,b,c;
int l1,l2,l3;
for(i=100;i<=999;i++){
a=i/100 ;
b=(i/10)%10;
c=i%10;
l1=pow(a,3);l2=pow(b,3);l3=pow(c,3);
if(l1+l2+l3==i){
printf("%d\n",i);
}
}
return 0;
}