Sum Problem 重定向文件的使用


Sum Problem

Problem Description

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>
//#define LOCAL
int main(){
    /*
    #ifdef LOCAL
    freopen("input.txt","r",stdin);//需要创建input.txt,里面写入1和100。
    freopen("output.txt","w",stdout);
    #endif
    */注释的代码用作文本输入输出。
    int i,n,s;
    while(scanf("%d",&n)!=EOF)
    {
        s=0;
        for(i=1;i<=n;i++){
            s+=i;
        }
        printf("%d

",s); 
    }
    return 0;
}



题目来源:http://acm.hdu.edu.cn/listproblem.php?vol=1

原文地址:https://www.cnblogs.com/shcsw/p/13261050.html