程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> printf-Sum Problem,簡單題不能ac

printf-Sum Problem,簡單題不能ac

編輯:編程解疑
Sum Problem,簡單題不能ac

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

int main()
{
int n;
while(scanf("%d",&n)==1)
{
int i;
int sum=0;
for(i=1;i<=n;i++)
sum+=i;
printf("%d",sum);
}
return 0;
}

最佳回答:


printf("%d",sum);
->
printf("%d\n",sum);

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved