博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Problem L: MULTIPLE TEST CASE 2:Calculation 1-2+3-4+...+n
阅读量:6998 次
发布时间:2019-06-27

本文共 484 字,大约阅读时间需要 1 分钟。

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

4100100010000100000

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;
}

转载于:https://www.cnblogs.com/ostrich-sugar/p/7787907.html

你可能感兴趣的文章