Sum Problem

[复制链接]
查看11 | 回复1 | 2014-12-23 14:59:46 | 显示全部楼层 |阅读模式
描述
Hey, welcome to TOJ(Taizhou University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
输入
The input will consist of a series of integers n, one integer per line.
输出
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
样例输入
1
100
样例输出
1
5050

回复

使用道具 举报

千问 | 2014-12-23 14:59:46 | 显示全部楼层
#include int main(){ int a,b,sum=0; int n; while(scanf("%d%d",&a,&b)!=EOF) {
for(n=a;n<=b;n++)sum+=n;
printf("%d\n",sum );sum=0; }
return 0;}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行