HDU-1001 calculate SUM(n) = 1 + 2 + 3 + ... + n.

简介: HDU-1001 calculate SUM(n) = 1 + 2 + 3 + ... + n.

题目:

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

解析:

1.不能使用等差数列求和公式

2.输出格式有两个换行符

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int  n;
    while(scanf("%d",&n)!=EOF){
            int sum=0;
    for(int i=1;i<=n;i++)
    {
        sum=sum+i;
    }
    printf("%d\n\n",sum);
    }
    return 0;
}


相关文章
|
算法
uva 11549 CALCULATOR CONUNDRUM
题目链接 刘汝佳算法竞赛经典入门训练指南p42
34 0
UVa11549 - Calculator Conundrum (Floyd判圈法)
UVa11549 - Calculator Conundrum (Floyd判圈法)
56 0
HDU-1012,u Calculate e
HDU-1012,u Calculate e
|
人工智能
Kuroni and Impossible Calculation——容斥原理-鸽笼原理-抽屉原理
题目描述 已知一个数组a[n],请计算式子:∏_{1≤i<j≤n}|ai−aj| 的值,其中1<=i,j<=n;我们可以认为,这一式子等价于 |a1−a2|⋅|a1−a3|⋅ … ⋅|a1−an|⋅|a2−a3|⋅|a2−a4|⋅ … ⋅|a2−an|⋅ … ⋅|an−1−an|
124 0
Kuroni and Impossible Calculation——容斥原理-鸽笼原理-抽屉原理
|
Go
HDOJ 1012 u Calculate e
HDOJ 1012 u Calculate e
112 0
HDOJ 1012 u Calculate e
|
C++
蓝桥杯 - C++ calculation
蓝桥杯 - C++ calculation
160 0
HDOJ 2114 Calculate S(n)(找周期)
HDOJ 2114 Calculate S(n)(找周期)
97 0
|
Java C语言
HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)
HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)
98 0