累加和

匿名 (未验证) 提交于 2019-12-02 23:35:02

累加和
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

题目描述:
编写程序,求自然数1至n(n>1)的累加和。其中n的值从键盘输入。(难度级别―容易)
Input

输入一个自然数赋给变量n。
Output

输出自然数1至n的累加和。
Sample Input

5
Sample Output

The sum of 1 to 5 is 15
Hint

Source

本文旨在为非计算机专业同学提供帮助

#include <stdio.h> int main()  { int n,i; scanf("%d",&n); int s=0; for(i=0;i<=n;i++)     s=s+i; printf("The sum of 1 to %d is %d",n,s); return 0; }  
文章来源: https://blog.csdn.net/qq_41938269/article/details/90573151
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!