Help me in solving LBCP01 problem

My issue

Hey Guys,

I don’t know what is the error in this problem. but the output showing correctly.
I will appreciate if you help me to fix it.

My code

// Update the program below to solve the problem

#include <stdio.h>

int main()
{
    int t;
    scanf("%d", &t); // Use scanf instead of cin in C

    while (t--)
    {
        int A, B, C;
        scanf("%d %d", &A, &C); // Use scanf instead of cin in C
        B = ((A+C)/2);
        
        if(A % 2 == 0 && C % 2 == 0)
        {
            printf("%d\n", A);
        }
        else if(A % 2 != 0 && C % 2 != 0)
        {
            printf("%d\n", B);
        }
        else
        {
            printf("%d\n", -1);
        }

        

    }

    return 0;
}

Learning course: Logic Building in C
Problem Link: CodeChef: Practical coding for everyone

@karnam_krishna
in first if condition u are printing A instead of B .

1 Like

@dpcoder_007 thanks for your response I figured it out