打卡第十四天
计算n的阶乘
一、
1.构造一个递归形式的阶乘函数
二、
三、
#include<iostream>
using namespace std;
unsigned hongyan(unsigned n)
{
unsigned f;
if(n==0)
f=1;
else
f=hongyan(n-1)*n;
return f;
}
int main()
{
int q;
cin>>q;
unsigned w;
w=hongyan(q);
cout<<q<<"的阶乘:"<<w<<endl;
return 0;
}
四、
#include<iostream>
using namespace std;
unsigned hongyan(unsigned n)
{
unsigned f;
if(n==0)
f=1;
else
f=hongyan(n-1)*n;
return f;
}
int main()
{
int q;
cin>>q;
unsigned w;
w=hongyan(q);
cout<<q<<"的阶乘:"<<w<<endl;
return 0;
}