当前位置:网站首页>Exercise 10-1 calculate the sum of 1 to n using recursive functions
Exercise 10-1 calculate the sum of 1 to n using recursive functions
2022-07-03 14:09:00 【ᯤ⁹ᴳ⁺ ·】
practice 10-1 Use recursive functions to calculate 1 To n The sum of the (10 branch )
This problem requires the realization of a recursive calculation 1+2+3+…+n Simple function of sum of .
Function interface definition :
int sum( int n );
This function is used for the positive integer passed in n return 1+2+3+…+n And ; if n If it is not a positive integer, return 0. The title guarantees that the input and output are in the long integer range . It is suggested to try to write recursive functions .
Sample referee test procedure :
#include <stdio.h>
int sum( int n );
int main()
{
int n;
scanf("%d", &n);
printf ("%d\n", sum(n));
return 0;
}
/* Your code will be embedded here */
sample input 1:
10
sample output 1:
55
sample input 2:
0
sample output 2:
0int sum( int n ){
int s;
if(n<=0){
s=0;
}else{
s=n+sum(n-1);
}
return s;
}

边栏推荐
- Fabric. JS document
- JS matrix zero
- Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)
- Current situation, analysis and prediction of information and innovation industry
- 【吉林大学】考研初试复试资料分享
- jvm-对象生命周期
- page owner特性浅析
- selenium 浏览器(1)
- TS code automatically generates JS
- Redis:Redis的数据结构、key的操作命令
猜你喜欢

Redis: operation command of string type data

JS Part III

TS code automatically generates JS

Richview trvstyle liststyle list style (bullet number)

小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
[email "/>Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email

QT learning 25 layout manager (4)

Summary of common error reporting problems and positioning methods of thrift

关于回溯问题中的排列问题的思考(LeetCode46题与47题)

Scroll detection, so that the content in the lower right corner is not displayed at the top of the page, but is displayed as the mouse slides
随机推荐
Uio-66-cooh loaded bendamostine | hydroxyapatite (HA) coated MIL-53 (FE) nanoparticles | baicalin loaded manganese based metal organic skeleton material
交联环糊精金属有机骨架负载甲氨蝶呤缓释微粒|金属-有机多孔材料UiO-66负载黄酮苷类药物|齐岳
JVM object lifecycle
Canvas utility library fabric JS user manual
Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)
Analysis of the characteristics of page owner
Message subscription and publishing
如何使用lxml判断网站公告是否更新
Go language web development series 29: Gin framework uses gin contrib / sessions library to manage sessions (based on cookies)
QT learning 24 layout manager (III)
好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录
Example analysis of QT learning 18 login dialog box
js 2023. String pair equal to the target string after connection
“又土又穷”的草根高校,凭什么被称为“东北小清华”?
Failure of vector insertion element iterator in STL
Common network state detection and analysis tools
[Jilin University] information sharing of postgraduate entrance examination and re examination
战略、战术(和 OKR)
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
Common mixins