Given a long integer, we need to find if the difference between sum of odd digits and sum of even digits is 0 or not. The indexes start from zero (0 index is for leftmost digit).
Input : 1212112 Output : Yes Explanation:- the odd position element is 2+2+1=5 the even position element is 1+1+1+2=5 the difference is 5-5=0.so print yes. Input :12345 Output : No Explanation:- the odd position element is 1+3+5=9 the even position element is 2+4=6 the difference is 9-6=3 not equal to zero. So print no.
Method 1: One by one traverse digits and find the two sums. If difference between two sums is 0, print yes, else no.
Method 2 : This can be easily solved using divisibility of 11. This condition is only satisfied if the number is divisible by 11. So check the number is divisible by 11 or not.
Please refer complete article on Difference between sums of odd and even digits for more details!
- Python Program for Check if all digits of a number divide it
- Python Program to create an OTP by squaring and concatenating the odd digits of a number
- Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Python program to find sum of absolute difference between all pairs in a list
- Python | Sum of number digits in List
- Python | Extract digits from given string
- Python - Test if all digits starts from % K digit
- Python | Merge Consecutive digits Strings
- Python | Remove all digits from a list of strings
- Python | Even Front digits Test in List
- Python | Sort list of numbers by sum of their digits
- Python | Convert list of tuples into digits
- Python Program for Efficient program to print all prime factors of a given number
- Python | Ways to remove numeric digits from given string
- Python | Split strings and digits from string list