n的阶乘 -牛客

题目描述

输入一个整数n,输出n的阶乘(每组测试用例可能包含多组数据,请注意处理)

输入描述:

一个整数n(1<=n<=20)

输出描述:

n的阶乘


解题思路

采用递归求解,也可以使用循环。

 1 #include <stdio.h>
 2 
 3 long jie(int x)
 4 {
 5     if(x==1) return 1;
 6     else return x*jie(x-1);
 7 }
 8 
 9 int main()
10 {
11     int n;
12     while(scanf("%d",&n)!=EOF)
13     {
14         printf("%ld
",jie(n));
15     }
16 }
原文地址:https://www.cnblogs.com/jiashun/p/newcode10.html