1 // 使用递归函数计算阶乘 2 3 #include<iostream> 4 using namespace std; 5 int Factorial(int n); 6 7 int main() 8 { 9 cout<<"计算n的阶乘:"<<endl; 10 int n; 11 cout<<"请输入n:"<<endl; 12 cin>>n; 13 cout<<"n的阶乘n!= "<<Factorial(n)<<endl; 14 return 0; 15 } 16 int Factorial(int n) 17 { 18 if(n<=1) 19 { 20 return 1; 21 } 22 else 23 { 24 return Factorial(n-1)*n; 25 } 26 }
转载于:https://www.cnblogs.com/yuzhuwei/p/4172682.html