c++ 递归求一个数的阶乘

#include <iostream>
using namespace std;
long factorial(int value);

int main() {
	int value;
	cout << "input number: ";
	cin >> value;
	cout << "factorial: " << factorial(value) << endl;
	return 0;
}

long factorial(int value) {
	if (value == 0) {
		return 1;
	}
	return value * factorial(value - 1);
}

  

posted @ 2018-09-28 20:01  ranwuer  阅读(783)  评论(0编辑  收藏  举报