注册 登录
编程论坛 C++教室

Sum Problem

lmyouya 发布于 2008-10-18 12:54, 934 次点击
Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).

In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.

Input
The input will consist of a series of integers n, one integer per line.

Output
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.

Sample Input
1
100
 

Sample Output
1

5050
6 回复
#2
hanpengqd2008-10-19 13:25
cn't you solve it ?
#3
lmyouya2008-10-19 14:46
[bo][un]hanpengqd[/un] 在 2008-10-19 13:25 的发言:[/bo]

cn't you solve it ?



sumit it many times, can't AC.

do it without the output format must be most simple!
#4
lmyouya2008-10-19 15:26
/*
*  It's Ok?It's Ok?It's Ok?It's Ok?It's Ok?
*/
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    while(std::cin>>a)
    {
        b=a*(1+a)/2;
        cout<<b<<endl<<endl;
    }
    return 0;
}
#5
blueboy820062008-10-19 15:47
[bo][un]lmyouya[/un] 在 2008-10-19 15:26 的发言:[/bo]

/*
*  It's Ok?It's Ok?It's Ok?It's Ok?It's Ok?
*/
#include
using namespace std;
int main()
{
    int a,b;
    while(std::cin>>a)
    {
        b=a*(1+a)/2;
        cout

挺好的,没什么问题...不知道过没...
#6
lmyouya2008-10-19 18:40
Run ID Submit Time          Judge Status  Pro.ID    Exe.Time  Exe.Memory  Code Len. Language
839085 2008-10-19 18:36:28  Wrong Answer  1001      0MS       140K        150B         C++

what's up? er, so fool am I!

[[it] 本帖最后由 lmyouya 于 2008-10-19 18:44 编辑 [/it]]
#7
lmyouya2008-10-20 21:50
今天终于AC了!
1