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
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; }
-
ACM需要的文本输入输出。重定向文件,具体请参考: