please help me find the problem.
Output is correct and also followed constraints bur cannot submit code
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 would be allowed.
Input:
1
00001
sum is 1 and it is odd.
if sum%3 ==0 then YES
1%3=1 therefore
Correct output --> NO
but according to you its YES. will you plz explain why ?
You have given a number and in that number, the digits which are even should have sum divisible by 4 or the sum of digits which are odd should be divisible by the 3, Only then you can say yes otherwise you will say no.
So the even sum of even digits is 0 and sum of odd digits is 1. We will print yes if evenSum % 4 == 0 || oddSum % 3 == 0. Now in this case we have, 0%4 is 0, and 1%3 is 1. Hence we print Yes
Suggested Approach:
- Take input of the Number.
- Declare two variables to store the sum of even numbers and odd numbers.
- Extract digit one by one ( by % 10).
-
Check if the number is even or odd.
-
If even add the number in the variable storing even sum.
-
- Othewise add it in the variable storing odd sum.
- After the loop, Check if the even sum is divisible by 4.
-
If True, print Yes.
-
otherwise print No.
-
- Check if the odd sum is divisible by 3.
-
If True, print Yes.
-
otherwise print No.
-
thankyou sanchit now i got the correct question.
written code again.
now for 00001 output is YES.
but not able to submit the code.plz check and help finding any error.
@Yuganshu,
https://ide.codingblocks.com/s/225622 corrected code
you are printing βYESβ instead of Yes.
And odd instead of No
