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.
This article is contributed by jaspal singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Possible two sets from first N natural numbers difference of sums as D
- First N natural can be divided into two sets with given difference and co-prime sums
- Absolute difference between the first X and last X Digits of N
- Nth positive number whose absolute difference of adjacent digits is at most 1
- Print all n-digit numbers with absolute difference between sum of even and odd digits is 1
- Count Numbers in Range with difference between Sum of digits at even and odd positions as Prime
- Count total number of N digit numbers such that the difference between sum of even and odd digits is 1
- Count of N-digit numbers with absolute difference of adjacent digits not exceeding K
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Count of numbers upto N digits formed using digits 0 to K-1 without any adjacent 0s
- Maximize the given number by replacing a segment of digits with the alternate digits given
- Find the average of k digits from the beginning and l digits from the end of the given number
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Check if the sum of digits of number is divisible by all of its digits
- Sum of square-sums of first n natural numbers
- Count number of ordered pairs with Even and Odd Sums
- Smallest Integer to be inserted to have equal sums