/*
*程序的版权和版本声明部分:
*Copyright(c)2013,烟台大学计算机学院学生
*All rights reserved.
*文件名称:
*作者:曹昕卓
*完成日期:2013年 11月13 日
*版本号:v1.0
*对任务及求解方法的描述部分:
*输入描述:
*问题描述:
*程序输出:
*问题分析:
*算法设计:
*/
#include<iostream>
using namespace std;
int fact(int);
int main()
{
int n,a,b,c,sum;
n=100;
while(n<1000)
{
//考察n是否符合要求
c=n%10;
b=(n/10)%10;
a=n/100;
sum=fact(a)+fact(b)+fact(c);
if(sum==n)
cout<<n<<" ";
++n;
}
return 0;
}
int fact(int n) //在设计中,函数的功能尽可能单一,fact只管求阶乘
{
int i, f=1;
for(i=1;i<=n;++i)
f=f*i;
return f;
}
成果展示: