天空是蓝色的

做好软件为中国 #gcc -c helloworld.c -o helloworld.o //编译目标文件 #gcc helloworld.o -o helloworld //编译成可执行exe #helloworld //运行exe
数据加载中……
水仙花问题
解法1
#include <stdio.h> 
int main() 

int shu
,bai,shi,ge; 
 for (shu=100;shu<1000;shu++) 
 { 
 bai
=shu/100; 
 shi=(shu-bai*100)/10; 
 ge=shu-bai*100-shi*10; 
 if(shu==(bai*bai*bai+shi*shi*shi+ge*ge*ge)) 
 printf(
"%d\n",shu); 
 } 

解法2
int main(){ 
int a
,b,c,num; 
for(a=1;a<10;a++){ 
for(b=0;b<10;b++){ 
for(c=0;c<10;c++){ 
if(a*100+b*10+c==(num=a*a*a+b*b*b+c*c*c)) 
printf(
"%d",num); 




posted on 2006-02-13 17:24 bluesky 阅读(557) 评论(1)  编辑  收藏 所属分类: C/C++

评论

# re: 水仙花问题 2008-07-10 12:24 

#include <stdio.h>
int main(void)
{
int a,b,c,d,e,f,g,h;
a=100;
for(g=0;g<899;g++)
{
a=a+1;
c=a/100;
d=(a-c*100)/10;
e=a-(c*100+d*10);
h=c*c*c+d*d*d+e*e*e;
if(h==a)
printf("%d,",a);
}
scanf("%d",f);
return f;
}
  回复  更多评论    

只有注册用户登录后才能发表评论。


网站导航: