#include <iostream>
using namespace std;
int fact(int n);
void testFact();
int main()
{
testFact();
return 0;
}
int fact(int n) {
int ret = 1;
while (n)
ret *= n--;
return ret;
}
void testFact() {
cout << "Enter an positive integer: ";
int n;
cin >> n;
cout << "factorial of " << n << " == "
<< fact(n) << endl;
}
fact() demo
最新推荐文章于 2021-03-02 15:56:55 发布