sir i wrote the codes for delhi odd even and count digits they are running and working completely fine but when i submitted the codes its showing test case 0 failed for delhi odd even and test case 0,1,2,3 failed for the count digits
Test case fail during submission
You logic is going wrong. Do a dry run and check it yourself.
What actually you are doing is that you are finding the sum of all digits and then checking its divisibility with 4 and 3 which is wrong. 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”.
sir but i am doing the sum of all digits and then checking if the number is odd and divisible by 3 or even and divisible by 4 if yes then i print ‘Yes’ or else i print ‘No’ and i have tried the code with many values and its giving the right ans
Read the question properly. It is mentioned “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.” But you are storing the sum of all the digits in your variable ans and then checking the condition on that.You have to find the sum of all digits which are even and the sum of all digits which are odd separately.
Consider a case:
4
32345
44444
33336
00001
Your O/p:
No
Yes
No
No
Expected O/p:
No
Yes
Yes
Yes
Try to correct your code now.
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.