Delhi's Odd Even

My code is not passing all the test cases.

#include
using namespace std ;

int main()
{
int n,no,sum=0,d;
cin>>n;

while(n!=0)
{
cin>>no;

while(no!=0)

{
d=no%10;
no/=10;
sum+=d;
}

if( (sum%2==0 && sum%4==0) )
{
	cout<<"Yes"<<endl;
}

else if( (sum%2==1 && sum%3==0) )

{
cout<<“Yes”<<endl;
}

 else
{
 cout<<"No"<<endl;
}

n--;

}

return 0;

}

@mvganeshk15
the logic of this problem
For ex if you are given a no.:

982452

then maintain 2 variables evesum=0, oddsum = 0 ;
and they will be:

9   +   8   +   2   +   4   +   5   +   2

evesum = 8 + 2 + 4 + 2 = 16
oddsum = 9 + 5 = 14
if((evesum%4==0)||(oddsum%3==0)){
cout<<“Yes”<<endl;
}else{
cout<<“No”<<endl;
}

1 Like

Respected Sir,

Thanks for solution now i can understand. Actually i misunderstood the problem ,i thought the sum of the digits are even and divisible by 4 instead of sum of even digits are divisible by 4.

Thanks
Ganesh

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.