水仙花数

/*“水仙花数”是指一个三位数,其各位数的立方和等于该。
例如:153=1的立方+5的立方+3的立方
编写程序:输出所有“水仙花数“
思路:1、取一个三位数,取百位,十位,个位。
      2、分别算出他们的立方和。
	  4、比较
*/
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
	int num;
	int bw,sw,gw;
	cout<<"水仙花数为"<<endl;
	for(num=100;num<1000;num++)
	{
		bw=num/100;
		sw=num%100/10;
		gw=num%10;
		if((pow(bw,3)+pow(sw,3)+pow(gw,3))==num)
			cout<<num<<endl;
	}
	return 0;
}


posted @ 2010-10-27 01:08  瓜蛋  阅读(174)  评论(0编辑  收藏  举报