course(递归专题)求n!的值
This commit is contained in:
parent
f837682d3a
commit
af24f23707
3
1659_n!/Readme.md
Normal file
3
1659_n!/Readme.md
Normal file
@ -0,0 +1,3 @@
|
||||
# 标题
|
||||
|
||||
* 内容
|
18
1659_n!/doc/Readme.md
Normal file
18
1659_n!/doc/Readme.md
Normal file
@ -0,0 +1,18 @@
|
||||
# 『入门』(递归专题)求n!的值
|
||||
[问题描述]
|
||||
|
||||
教学案例,必须使用递归函数完成求解!
|
||||
|
||||
n!=1*2*...*n。例:5!=1*2*3*4*5=120。编程求:n!=?
|
||||
|
||||
[输入格式]
|
||||
一个整数n,( n <= 15 )
|
||||
|
||||
[输出格式]
|
||||
一个整数,n!的运算结果。
|
||||
|
||||
[输入样例]
|
||||
3
|
||||
|
||||
[输出样例]
|
||||
6
|
15
1659_n!/main.cpp
Normal file
15
1659_n!/main.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
//½×³Ë£¨³¬Ð¡£©
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
long long dg(long long n){
|
||||
if(n==1){
|
||||
return 1;
|
||||
}
|
||||
return n+dg(n-1);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin>>n;
|
||||
cout<<dg(n);
|
||||
}
|
BIN
1659_n!/main.exe
Normal file
BIN
1659_n!/main.exe
Normal file
Binary file not shown.
1
1659_n!/test/in.txt
Normal file
1
1659_n!/test/in.txt
Normal file
@ -0,0 +1 @@
|
||||
1
|
1
1659_n!/test/in2.txt
Normal file
1
1659_n!/test/in2.txt
Normal file
@ -0,0 +1 @@
|
||||
15
|
1
1659_n!/test/in3.txt
Normal file
1
1659_n!/test/in3.txt
Normal file
@ -0,0 +1 @@
|
||||
4
|
18
1659_n!/test/out.txt
Normal file
18
1659_n!/test/out.txt
Normal file
@ -0,0 +1,18 @@
|
||||
## z:\Chao\src\1659_n!\test\in.txt
|
||||
2020/04/24 周五 13:42:16.59
|
||||
1
|
||||
-----------------------------------------------
|
||||
Process exited after 190 ms with return value 0
|
||||
|
||||
## z:\Chao\src\1659_n!\test\in2.txt
|
||||
2020/04/24 周五 13:42:16.59
|
||||
1307674368000
|
||||
-----------------------------------------------
|
||||
Process exited after 100 ms with return value 0
|
||||
|
||||
## z:\Chao\src\1659_n!\test\in3.txt
|
||||
2020/04/24 周五 13:42:16.59
|
||||
24
|
||||
-----------------------------------------------
|
||||
Process exited after 110 ms with return value 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user