【深基7.例7】计算阶乘
题目描述
求 n ! n! n!,也就是 1 × 2 × 3 ⋯ × n 1\times2\times3\dots\times n 1×2×3⋯×n。
挑战:尝试不使用循环语句(for、while)完成这个任务。
输入格式
第一行输入一个正整数 n n n。
标题
输出格式
输出一个正整数,表示 n ! n! n!。
样例 #1
样例输入 #1
3
样例输出 #1
6
提示
数据保证, 1 ≤ n ≤ 12 1 \leq n\le12 1≤n≤12。
c++解答:
#include<iostream>
using namespace std;
int fun(int t){
if(t==0||t==1){
return 1;
}
return t*fun(t-1);
}
int main(){
int n;
cin>>n;
long long res = fun(n);
cout<<res;
return 0;
}