Sum of odd and even elements

时间:2023-01-08 22:00:43

Given an integer N, you have to print the sum of odd numbers and even numbers form 1 to N

Input:
First line consists of T test cases. First line of every test case consists of a Single integer N.

Output:
Single line output, with sum of odd numbers and even numbers respectively.

Constraints:
1<=T<=100
1<=N<=10^5

Example:
Input:
2
5
6
Output:
9 6
9 12

下面是我的代码实现:注意,这里需要长整形,不然当输入过大时候,就会发生溢出现象。

#include <stdio.h>

int main() {
    int n,i,j;//n组实例
    scanf("%d",&n);
    ;i<n;i++)
    {
        ,sum2=;//num是输入的数,sum1是奇数和,sum2偶数和
        scanf("%d",&num);
        ;j<=num;j++)
        {
            ==)
            {
                sum1=j+sum1;
            }
            else
            {
                sum2=j+sum2;
            }
        }
        printf("%ld ",sum1);
        printf("%ld\n",sum2);
    }
    ;
}

如有问题,请留言。