HDOJ-1001 Sum Problem

简介: Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).

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

水题

#include<stdio.h>
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        int sum=0,i;
        for(i=1;i<=n;i++){
            sum+=i;
        }
        printf("%d\n\n",sum);
    }
    return 0;
}
目录
相关文章
HDOJ 1016 Prime Ring Problem素数环【深搜】
HDOJ 1016 Prime Ring Problem素数环【深搜】
123 0
HDOJ 1016 Prime Ring Problem素数环【深搜】
HDOJ 2058 The sum problem
HDOJ 2058 The sum problem
118 0
HDOJ 1001Sum Problem
HDOJ 1001Sum Problem
122 0
HDOJ 1002 A + B Problem II
HDOJ 1002 A + B Problem II
125 0
HDOJ 2101 A + B Problem Too
HDOJ 2101 A + B Problem Too
110 0
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
131 0
|
Java
HDOJ 1000 A + B Problem
HDOJ 1000 A + B Problem
117 0
|
Java 文件存储
HDOJ(HDU) 2132 An easy problem
HDOJ(HDU) 2132 An easy problem
119 0
|
Java 文件存储
HDOJ(HDU) 2123 An easy problem(简单题...)
HDOJ(HDU) 2123 An easy problem(简单题...)
183 0
|
C语言
HDOJ 1016 Prime Ring Problem素数环【深搜2】
HDOJ 1016 Prime Ring Problem素数环【深搜】
102 0