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).

Examples:

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.

## CPP

`// C++ program to check if difference between sum of ` `// odd digits and sum of even digits is 0 or not ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `bool` `isDiff0(` `long` `long` `int` `n) ` `{ ` ` ` `return` `(n % 11 == 0); ` `} ` ` ` `int` `main() { ` ` ` ` ` `long` `int` `n = 1243 ` ` ` `if` `(isDiff0(n)) ` ` ` `cout << ` `"Yes"` `; ` ` ` `else` ` ` `cout << ` `"No"` `; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to check if difference between sum of ` `// odd digits and sum of even digits is 0 or not ` ` ` `import` `java.io.*; ` `import` `java.util.*; ` ` ` `class` `GFG ` `{ ` ` ` `public` `static` `boolean` `isDiff(` `int` `n) ` ` ` `{ ` ` ` `return` `(n % ` `11` `== ` `0` `); ` ` ` `} ` ` ` `public` `static` `void` `main (String[] args) ` ` ` `{ ` ` ` `int` `n = ` `1243` `; ` ` ` `if` `(isDiff(n)) ` ` ` `System.out.print(` `"Yes"` `); ` ` ` `else` ` ` `System.out.print(` `"No"` `); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python

`# Python program to check if difference between sum of ` `# odd digits and sum of even digits is 0 or not ` ` ` `def` `isDiff(n): ` ` ` `return` `(n ` `%` `11` `=` `=` `0` `) ` ` ` `# Driver code ` `n ` `=` `1243` `; ` `if` `(isDiff(n)): ` ` ` `print` `(` `"Yes"` `) ` `else` `: ` ` ` `print` `(` `"No"` `) ` ` ` `# Mohit Gupta_OMG <0_o> ` |

*chevron_right*

*filter_none*

## C#

`// C# program to check if difference ` `// between sum of odd digits and sum ` `// of even digits is 0 or not ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `public` `static` `bool` `isDiff(` `int` `n) ` ` ` `{ ` ` ` `return` `(n % 11 == 0); ` ` ` `} ` ` ` ` ` `public` `static` `void` `Main () ` ` ` `{ ` ` ` `int` `n = 1243; ` ` ` ` ` `if` `(isDiff(n)) ` ` ` `Console.WriteLine(` `"Yes"` `); ` ` ` `else` ` ` `Console.WriteLine(` `"No"` `); ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to check if ` `// difference between sum of ` `// odd digits and sum of ` `// even digits is 0 or not ` ` ` `function` `isDiff0(` `$n` `) ` `{ ` ` ` `return` `(` `$n` `% 11 == 0); ` `} ` ` ` ` ` `// Driver Code ` ` ` `$n` `= 1243; ` ` ` `if` `(isDiff0(` `$n` `)) ` ` ` `echo` `"Yes"` `; ` ` ` `else` ` ` `echo` `"No"` `; ` ` ` `// This code is contributed by nitin mittal ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Yes

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 contribute@geeksforgeeks.org. 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.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Count of integers in a range which have even number of odd digits and odd number of even digits
- Count number of ordered pairs with Even and Odd Sums
- Check if a number has an odd count of odd divisors and even count of even divisors
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Count total number of N digit numbers such that the difference between sum of even and odd digits is 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
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Check if product of digits of a number at even and odd places is equal
- Find the sum of digits of a number at even and odd places
- Check if the number is even or odd whose digits and base (radix) is given
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers
- Queries on sum of odd number digit sums of all the factors of a number
- Smallest odd number with even sum of digits from the given number N
- Minimum digits to be removed to make either all digits or alternating digits same
- First N natural can be divided into two sets with given difference and co-prime sums
- Possible two sets from first N natural numbers difference of sums as D
- Partition a set into two non-empty subsets such that the difference of subset sums is maximum