Description
用递归算法,求N!的精确值(N以一般整数输入)。
Sample Input 1
10
Sample Output 1
10!=3628800
Source
递归
这里我用的是long long 定义的,其实也可以用int 的
#include<bits/stdc++.h>
using namespace std;
long long x(long long a){
if(a==1) return 1;
return a*x(a-1);
}
int main(){
long long n;
cin>>n;
cout<<n<<"!="<<x(n);
return 0;
}
这里当a==1的时候返回就是1,否则就递归
感兴趣的话点个赞吧!