course(递归专题)求累加和

This commit is contained in:
James 2020-04-24 13:51:38 +08:00
parent e862efa6c7
commit 19ac0b6144
8 changed files with 57 additions and 0 deletions

3
1660_n+/Readme.md Normal file
View File

@ -0,0 +1,3 @@
# 标题
* 内容

18
1660_n+/doc/Readme.md Normal file
View File

@ -0,0 +1,18 @@
# 『入门』(递归专题)求累加和
[问题描述]
教学案例,必须使用递归函数完成求解!
  编程求解下列式子的值s=1+2+3+...+n。
[输入格式]
  一行只有一个整数n。(1 <= n <= 1000)
[输出格式]
  1个整数即s的值。
[输入样例]
100
[输出样例]
5050

15
1660_n+/main.cpp Normal file
View 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
1660_n+/main.exe Normal file

Binary file not shown.

1
1660_n+/test/in.txt Normal file
View File

@ -0,0 +1 @@
1

1
1660_n+/test/in2.txt Normal file
View File

@ -0,0 +1 @@
100

1
1660_n+/test/in3.txt Normal file
View File

@ -0,0 +1 @@
1000

18
1660_n+/test/out.txt Normal file
View File

@ -0,0 +1,18 @@
## z:\Chao\src\1660_n+\test\in.txt
2020/04/24 周五 13:47:20.56
1
-----------------------------------------------
Process exited after 160 ms with return value 0
## z:\Chao\src\1660_n+\test\in2.txt
2020/04/24 周五 13:47:20.56
5050
-----------------------------------------------
Process exited after 80 ms with return value 0
## z:\Chao\src\1660_n+\test\in3.txt
2020/04/24 周五 13:47:20.56
500500
-----------------------------------------------
Process exited after 80 ms with return value 0