For a given N, prints the sum of even and odd integers of the first N natural numbers.

First line of the input contains an integer T which denotes the number of test cases. Then T test cases follow.  Each test case contains a single line containing N.

Output: 
For each test case, print space separated sums of even and odd integers of the first N natural numbers respectively.
Constraints:
1 <= T< = 200
1<=N<=10000
Example:
Input:

2
1

Output:
0 1
12 9 


 


CODE:

import java.util.*;
import java.lang.*;
import java.io.*;
class GFG 
{
public static void main (String[] args) 
{
//code
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
while(n>0)
{
    int i,natural_num,even=0,odd=0;
    natural_num=sc.nextInt();
        for(i=1;i<=natural_num;i++)
        {
            if(i%2==0)
                even+=i;
            else
                odd+=i;
        }
           System.out.println(even+" "+odd);
        n--;
}
}
}




Comments

Popular posts from this blog

Playing with mobile numbers