实验思路:求n的阶乘,可看作是n乘以(n-1)的阶乘,以此类推,就可求得n的阶乘,这时用递归函数最好。
#include <iostream>
using namespace std;
unsigned Fac(unsigned a){
if(0 == a || 1 == a)
return 1;
else
return a * Fac(a - 1);
}
int main(){
unsigned n;
cout << "Please enter a non-negative integer not greater than 10 " << endl;
cin >> n;
if(n > 10 || n < 0)
cout << "Input error" << endl;
cout << "The order multiplication of this number is " << Fac(n) << endl;
return 0;
}