#include <stdio.h>
int main()
{int sum=0;
int N,m;
scanf("%d",&m);
for(m=100;m<=N;m++){
int a=m%10;
int b=(m/10)%10;
int c=m/100;
if(m==aaa+bbb+ccc)
printf("%d\n",m);
sum=sum+m;}
printf("%d\n",sum);
}
#include <stdio.h>
int main()
{int sum=0;
int N,m;
scanf("%d",&m);
for(m=100;m<=N;m++){
int a=m%10;
int b=(m/10)%10;
int c=m/100;
if(m==aaa+bbb+ccc)
printf("%d\n",m);
sum=sum+m;}
printf("%d\n",sum);
}
修改如下,供参考:
#include <stdio.h>
int main()
{
int sum = 0;
int N, m;
scanf("%d", &N);
for (m = 100; m <= N; m++) {
int a = m % 10;
int b = (m / 10) % 10;
int c = m / 100;
if (m == a * a * a + b * b * b + c * c * c)
{
printf("%d\n", m);
sum = sum + m;
}
}
printf("%d\n", sum);
return 0;
}