?? factory.cpp
字號:
//=====================================
// title: 用遞歸(recurrence)方法實現(xiàn)階乘 recursion
// author: cjj
// date: 2007-10-2
//=====================================
/*
n!=n*(n-1)!
if n=1 or n=0, n!=1.
*/
#include <iostream>
using namespace std;
int factory(int n);
int main()
{
//if the input number is 111, then the program stop.
for (int n; cin >> n && n != 111;)
{
cout << n << "! = " << factory(n) << endl;
}
return 0;
}
int factory(int n)
{
//if (n == 0 || n == 1)
if(n<2) return 1;
return n * factory(n - 1);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -