#include
using namespace std;
int main(){
int N;
cin>>N;
int no;
for(int i=1;i<=N;i++){
cin>>no;
int sum_of_digit=0;
while(no>0){
int digit= no%10;
sum_of_digit = sum_of_digit + digit;
no=no/10;
}
if(sum_of_digit%2==0 && sum_of_digit%4==0){
cout<<“Yes”<<endl;
}
else if(sum_of_digit%2==0 && sum_of_digit%4!=0){
cout<<“No”<<endl;
}
else if(sum_of_digit%2!=0 && sum_of_digit%3==0){
cout<<“Yes”<<endl;
}
else if(sum_of_digit%2!=0 && sum_of_digit%3!=0){
cout<<“No”<<endl;
}
else{
cout<<“No”<<endl;
}
}
return 0;
}
Please help me know the error in my code and why its not working for all test cases
please read question carefully
each car will be allowed to run on Sunday if the sum of digits which are even is divisible by 4 or sum of digits which are odd in that number is divisible by 3. However to check every car for the above criteria can’t be done by the Delhi Police.
you have to consider 2 variables
oddDigtSum and evenDigitSum
now extract digits form number and add accordingly
like this
while(no>0){
int digit=no%10;
if(digit%2==0){
// digit is even so add to evenDigitSum
evenDigitSum+=digit;
}
else{
// digit is odd so add to oddDigitSum
oddDigitSum+=digit;
}
no=no/10;
}
now after that you have to check the condition given in question
if(evenDigitSum%4==0||oddDigitSum%3==0){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like
: and don’t forgot to mark doubt as resolved 
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.