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;
}
目录
相关文章
LeetCode 39. Combination Sum
给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 candidates 中的数字可以无限制重复被选取。
55 0
LeetCode 39. Combination Sum
LeetCode 216. Combination Sum III
找出所有相加之和为 n 的 k 个数的组合。组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字。
79 0
LeetCode 216. Combination Sum III
HDOJ 2058 The sum problem
HDOJ 2058 The sum problem
89 0
HDOJ 1001Sum Problem
HDOJ 1001Sum Problem
92 0
HDOJ 2101 A + B Problem Too
HDOJ 2101 A + B Problem Too
84 0
HDOJ 1002 A + B Problem II
HDOJ 1002 A + B Problem II
96 0
|
Go
HDOJ(HDU) 1977 Consecutive sum II(推导、、)
HDOJ(HDU) 1977 Consecutive sum II(推导、、)
87 0
HDOJ(HDU) 2136 Largest prime factor(素数筛选)
HDOJ(HDU) 2136 Largest prime factor(素数筛选)
89 0
|
Java
HDOJ 1000 A + B Problem
HDOJ 1000 A + B Problem
88 0
HDOJ(HDU) 1673 Optimal Parking
HDOJ(HDU) 1673 Optimal Parking
101 0