求阶乘,输入一个正整数 n,输出n!

时间:2022-06-10 15:13:06

#include<stdio.h>
int factorial (int n);

int main(){
int n;

scanf("%d",&n);
printf("%d \n",factorial(n));

return 0;
}

int factorial(int n){

int i,fact=1;

for(i=1;i<=n;i++)
fact = fact*i;

return fact;

}

求阶乘,输入一个正整数 n,输出n!