Skip to content

819. 递归求阶乘 #7

@RyanHe0

Description

@RyanHe0

请使用递归的方式求 n 的阶乘。

输入格式

共一行,包含一个整数 n

输出格式

共一行,包含一个整数,表示 n
的阶乘的值。

数据范围

1≤ n ≤10

#include<iostream>
using namespace std;
int fact(int n){
    int ans=1;
    if (n<2) return ans;
    else return fact(n-1)*n;
}
int main(){
    int in;
    cin>>in;
    cout<<fact(in);

} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions