版主救命~
1068. SumTime Limit: 2.0 second
Memory Limit: 16 MB
Your task is to find the sum of all integer numbers lying between 1 and N inclusive.
Input
The input consists of a single integer N that is not greater than 10000 by it's absolute value.
Output
Write a single integer number that is the sum of all integer numbers lying between 1 and N inclusive.
#include "stdio.h"
int main()
{
int n,sum = 0;
int i;
scanf("%d",&n);
if(n > 10000)
return 0;
if(n < 0)
{
for( i = n; i <=0;i ++)
{
sum += i;
}
sum += 1;
}
else
{
for(i = 0;i <= n;i ++)
{
sum += i;
}
}
printf("%d\n",sum);
return 0;
}
//////////
#include "stdio.h"
#include "math.h"
int main()
{
int n,sum = 0;
int i;
scanf("%d",&n);
if(n > 10000)
return 0;
printf("%d\n",(n + 1) * (abs(n - 1) + 1)/2);
return 0;
}
上面是一个acm简单题的两个不同的程序,测试数据相同 结果相同,为什么上面一个通不过,下面一个却可以 。。。