C和C++编程,求水仙花数

来源:互联网 发布:mac spctl是什么指令 编辑:程序博客网 时间:2024/05/17 04:26

OS:win7 64bit,编译工具:VS2010

给本科生助教后,想起来了,觉得数字很神奇吗,就自己写了下,挺简单的,直接上代码:

//-------------------------//Author:SpeedyF//Date.Time://Version://--------------------------#include <stdio.h>#include <math.h>#include <iostream>//#include <cmath>using namespace std;int main(){unsigned int a, b, c;printf("下面将要输出满足要求的所有水仙花数(三位整数)\n");for(int i =100; i<= 999; i++ ){a = i/100; // 百位数b = (i-a*100)/10; //十位数c = i- a*100-b*10;//个位数if(i == a*a*a+b*b*b+c*c*c)//if(i==pow((float)a,3)+pow((float)b,3)+pow((float)c,3))printf("%d\n",i);}cout<<"---Test Below---\n"<<pow((float)2,5)<<endl;    //testreturn 0;}

编译运行结果:



                                                                                                                                                                                                                  

                                                                                                                                                                                                 ——夙风.书于.2015.04.28

0 0