求n的阶乘。
#include<iostream>
using namespace std;
unsigned fac(unsigned m)
{
unsigned n;
if(m==0)
n=1;
else
n=fac(m-1)*m;
return n;
}
int main()
{
unsigned x,y;
cin>>x;
y=fac(x);
cout<<y;
return 0;
}
求n的阶乘。
#include<iostream>
using namespace std;
unsigned fac(unsigned m)
{
unsigned n;
if(m==0)
n=1;
else
n=fac(m-1)*m;
return n;
}
int main()
{
unsigned x,y;
cin>>x;
y=fac(x);
cout<<y;
return 0;
}