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,SUM; while(scanf("%d",&n)!=0) { SUM=n*(n+1)/2; printf("%d\n",SUM); printf("\n"); } return 0; }【错误分析】题目中限制结果在32位以内,但是公式n*(n+1)/2已经超出限制,可将公式改为n*(n+1)/2.0,或者用sum+=i。【正确答案】#include <stdio.h> int main() { int n,SUM,i; while(scanf("%d",&n)!=EOF) { SUM=0; for(i=1;i<=n;i++) SUM+=i; printf("%d\n",SUM); printf("\n"); } return 0; }