Sunkeerth Muppala
Sunkeerth Muppala

Reputation: 21

Need help figuring out why one of my test cases isn't passing

https://codeforces.com/contest/4/problem/A

This is a summary of the problem.

I initially started out with a function which checks whether the input numbers or even or not, then by using a for loop which scrolls through numbers from 1 to the given number.

I've used another variable to store the complement(i.e 8=1+7,2+6,3+5 and so on)

#include<stdio.h>
#include<stdlib.h>

int check_even(int,int);
int main()
{
    int n,i,m;
    int a;
    scanf("%d", &n);
    if(n<=100&&n>0)//checking the weight conditions for the watermelon
    {
        for(i=1;i<=n;i++)
        {
            m=n-i;
            a=check_even(m,i);//checking whether both no are even
            if (a==0)
                break;
            else
                continue;
        }
        if(a==0)
            printf("YES");
        else if(a==1)
            printf("NO");
    }
    return 0;
}
int check_even(int m,int i)
    {
        if(m%2==0 && i%2==0)//checking for even no.
            return 0;
        else
            return 1;
    }

The case where I'm getting stuck is n=2 2=1+1, both are odd hence output should be "NO", but I repeatedly keep getting "YES".

Upvotes: 1

Views: 83

Answers (1)

ComplicatedPhenomenon
ComplicatedPhenomenon

Reputation: 4189

In the for loop. first you check_even(1,1) which returns 1, so a is 1, therefore the loop continues, check_even(0,0) and returns 0, and a is 0 now so it print YES. Actually you should set for(i=1;i<n;i++).

Upvotes: 1

Related Questions