⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 factory.cpp

📁 阶乘的C++实现方法
💻 CPP
字号:
//=====================================
// title: 用递归(recurrence)方法实现阶乘 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);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -