HDU_acm_1001
Text Reverse
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + … + n.
Sample Input
1
100
Sample Output
1
5050
在做题过程中遇到了 一个问题,Time Limit Exceeded,即超过时间限制。于是修改代码,最开始的代码是只用了循环去完成要求,看见提示后改用函数,但是根据它的提示好像用掉的时间是一样的…我自闭了
为什么这样能ac!!!???
#include<stdio.h>
int main(){
int n, i, sum;
while(scanf("%d", &n) != EOF){
sum = 0;
for(i = 1; i <= n; i++)
sum = sum + i;
printf("%d\n\n", sum);
}
return 0;
}