6-8 简单阶乘计算(10 分)

#include 

int Factorial( const int N );

int main()
{
    int N, NF;

    scanf("%d", &N);
    NF = Factorial(N);
    if (NF)  printf("%d! = %d\n", N, NF);
    else printf("Invalid input\n");

    return 0;
}
int Factorial( const int N ){
    if( N < 0 ) return 0;
    else{
        int jiecheng = 1 ;
        for(int i = 2 ; i <= N ; i++ ){
            jiecheng = jiecheng * i ;
        }
        return jiecheng ;
    }
}

 

你可能感兴趣的:(PTA,基本编程题)