提示:如果三位数ABC满足ABC=A3+B3+C3,则称其为水仙花数
废话不多说,直接上代码,注意看注释要对自己负责
#define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; //用递归求某一项的阶乘的值 int fun(int i)//求第i项的值 { if (1 == i) return 1; return fun(i - 1) * i;//返回某一项阶乘的值 } //用递归求某些项阶乘的和 int fun1(int i)//求前i项阶乘的和 { if (1 == i) return 1; return fun1(i - 1) + fun(i);//返回某些阶乘和的值 } void test01() { cout << "输出1到20的阶乘的和fun1(20):" << fun1(20) << endl; } int main(void) { test01(); system("pause"); return 0; }
编辑