Description

Calculation 1 -2 +3 -4+...+n

Input

Input repeat times  m  first,  then  input n each  time.

Output

outut  sum of  1 -2 +3 -4+...+n

Sample Input

4
100
1000
10000
100000

Sample Output

-50
-500
-5000
-50000

HINT

 

#include<stdio.h>
int main()
{
int i,m,n,t;
long long sum;
scanf("%d",&m);
for(i=1;i<=m;i++)
{
scanf("%d",&n);
sum=0;
for(t=1;t<=n;t++)
{if(t%2==0)
{sum=sum-t;}
if(t%2==1)
{sum=sum+t;}}
printf("%lld\n",sum);}
return 0;
}

posted on 2017-11-05 17:17  鸵鸟tang  阅读(102)  评论(0编辑  收藏  举报