#include <iostream>
using namespace std;
long mul(long);
int main() {
long mu, x;
for (;;) {
cout << "Enter a number: ";
cin >> x;
mu = mul(x);
cout << x << "!= " << mu << endl;
}
}
long mul(long x) {
if (x > 1)
x *=mul(x - 1);
return x;
}
/**********************
Enter a number: 1
1!= 1
Enter a number: 2
2!= 2
Enter a number: 3
3!= 6
Enter a number: 4
4!= 24
Enter a number: 5
5!= 120
Enter a number: 6
6!= 720
Enter a number: 7
7!= 5040
Enter a number: 8
8!= 40320
Enter a number: 9
9!= 362880
Enter a number: 10
10!= 3628800
**********************/
c++ primer plus 第七章-编程题7.13.5《求任意一个数的阶乘》
最新推荐文章于 2022-12-23 19:46:11 发布