Odd even problem

My code is giving the correct output then why after submitting its showing wrong,kindly tell ! Below is the code:
#include
using namespace std;
int main() {
int N;
cin>>N;
int n;
int cnt=0;
while(cnt<N){
cin>>n;
int ans=0;
while(n!=0){
int r=n%10;
ans=ans+r;
n=n/10;
}
if(ans%2==0 and ans%4==0){
cout<<“yes”<<endl;
}
else if(ans%2!=0 and ans%3==0){
cout<<“yes”<<endl;
}
else{
cout<<“no”;
}
cnt++;

}
return 0;

}

You have to find the sum of all digits which are even and the sum of all digits which are odd separately. If the sum of all even digits is divisible by 4 or sum of all odd digits is divisible by 3, then only print “Yes”. In all other cases print “No”.
So if digit is odd, you add it to odd sum. And if digit is even, you add it to even sum.
Try to correct your code now.

oh that means if my no is 12134 the i have to find um of odd digits and even digits in this no like 1+1+3 and if it is divisible by 4 the i have to print yes?

Yes…follow the logic as i have explained above.
Maintain a variable oddsum which will store the sum of all odd digits
and a variable evensum which will store the sum of all even digits

1 Like

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.