急求一道c语言程序设计题!多谢多谢!拜托了!

来源:百度知道 编辑:UC知道 时间:2024/06/06 20:21:08
输出所有的"水仙花数",所谓水仙花数是指一个3位数,其各位数字立方和等于该数本身.例如,153是水仙花数,因为 153等于1的立方+5的立方+3的立方

#include "stdio.h"

int main()
{
int trifig,hunth,tenth,oneth;
clrscr();
for(trifig=100;trifig<1000;trifig++)
{
hunth=trifig/100;
tenth=trifig/10%10;
oneth=trifig%10;
if(trifig==(hunth*hunth*hunth+tenth*tenth*tenth+oneth*oneth*oneth))
printf("\t%d\t",trifig);
}
getch();
return 0;
}

main()
{int g,s,b;
int i;
for(i=100;i<1000;i++)
{
b=i/100;
s=i%100/10;
g=i%10;
if(i==b*b*b+s*s*s+g*g*g)
printf("%3d\n",i);
}
}


#include <iostream>
using namespace std;
void main()
{
int d1,d2,d3,temp;
for(int i=100;i<1000;i++)
{
d1=i/100;//取得百位数
temp=i%100;
d2=temp/10;//取得十位数
temp=temp%10;
d3=temp;//取得个位数
if(d1*d1*d1+d2*d2*d2+d3*d3*d3==i)
cout<<"the daffodil number is "<<i<<