水仙花数四种输出方法总结

水仙花数四种输出方法总结

##适用于Dev c++中编译运行
/*使用for循环输出

#include<stdio.h>
int main(void){
	int a,b,c,d;
	for(a=100;a<1000;a++)  /*a为所要寻找的三位数,b为百位,c为十位,d为个位*/ 
	{
		b=a/100;
		c=(a-b*100)/10;
		d=a%10;
		if(b*b*b+c*c*c+d*d*d==a){
			printf("%d\n",a);
		}
	}
	return 0;
}

/*使用do-while方式输出

#include<stdio.h>
int main(void){
 	int a,b,c,d; /*a为所要寻找的三位数,b为百位,c为十位,d为个位*/ 
 	a=100;
do{
	 b=a/100;
     c=a/10%10;  
 	 d=a%10;
 	 if(b*b*b+c*c*c+d*d*d==a){
 	 	printf("%d\n",a);
	  }
 	 a=a+1;/*a++*/
}while(a<1000);  
 	return 0; 
  }  
  

/*使用while方式输出

#include<stdio.h>
int main(void){
	int a,b,c,d; //a为三位数 
	a=100;
	while(a<1000){
		b=a/100;
		c=(a-b*100)/10;
		d=a%10;
		if(b*b*b+c*c*c+d*d*d==a)
		printf("%d\n",a); 
		a++;
	}
	return 0;
}

/*使用loop-goto语句输出

#include<stdio.h>
int main(void){
 	int a,b,c,d; /*a为所要寻找的三位数,b为百位,c为十位,d为个位*/ 
 	a=100;
loop:
	 b=a/100;
     c=a/10%10;  
 	 d=a%10;
if(b*b*b+c*c*c+d*d*d==a)
 	    printf("%d\n",a);
 	    a=a+1;/*a++*/
if(a<1000)
 	goto loop;
 	return 0; 
  } 
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晚秋ovo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值