Sum ProblemTime Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 559426 Accepted Submission(s): 141821 Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). 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 Author DOOM III Recommend We have carefully selected several similar problems for you: 1002 1090 1003 1091 1004 |
Tip:
1、注意输出格式(两个换行符)
但是我还是wrong answer了
2、正确的为把int sum=0;放进while循环里面
多组输入,每次sum都是0啊啊啊啊啊
#include <iostream>
using namespace std;
int main() {
int a;
while(cin>>a){
int sum=0;//多组输入,每次sum都是0啊啊啊啊啊
for(int i=1;i<=a;i++){
sum=sum+i;
}
cout<<sum<<endl<<endl;
}
return 0;
}