筷子与饺子
Published on 2019-11-11 04:08 in 暂未分类 with 筷子与饺子

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\n",jie(n));
15     }
16 }

 

posted @ 2019-08-11 10:37  筷子与饺子  阅读(385)  评论(0编辑  收藏  举报