# Check if a + b = c is valid after removing all zeroes from a, b and c

Given two integers a and b. Now, c can be found as a + b = c. The task is to check if the equation is still valid after removing all zeroes from a, b and c. If valid then print Yes else print No.

Examples:

Input: a = 101, b = 102
Output: Yes
Current equation is 101 + 102 = 203
After removing 0s, 11 + 12 = 23 (which is still correct)

Input: a = 105, b = 106
Output: No
105 + 106 = 211
15 + 16 = 211 (Incorrect)

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach:

• Calculate c.
• Remove all 0s from a, b and c.
• Check if the new values form a correct equation.

Below is the implementation of the above approach:

## C++

 `// C++ implementation of the approach ` `#include ` `#include ` `#include ` `#include ` ` `  `using` `namespace` `std; ` ` `  `// Function to remove zeroes from a number ` `int` `remove``(``int` `x) ` `{ ` `    ``// Converting x into a string ` `     `  `    ``string y = to_string(x); ` `     `  `    ``// To store the new integer without 0s ` `    ``string num; ` `    ``int` `i; ` `    ``for``(i = 0; i < y.length(); i++) ` `    ``{ ` `        ``// Skip if current character is 0 ` `        ``if``(y[i] == 0) ` `            ``continue``; ` `        ``num += y[i]; ` `    ``} ` `         `  `    ``// Return the integer after removing 0s ` `    ``return` `stoi(num); ` `}  ` ` `  `// Function that returns true if  ` `// the given condition is satisfied ` `bool` `check(``int` `a, ``int` `b) ` `{  ` `    ``// Calculate c ` `    ``int` `c = a + b; ` `     `  `    ``// Remove 0s from a, b and c ` `    ``a = ``remove``(a); ` `    ``b = ``remove``(b); ` `    ``c = ``remove``(c); ` `     `  `    ``// Check if the equation is still correct ` `    ``if``((a + b) == c) ` `        ``return` `true``; ` `    ``else` `        ``return` `false``; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``int` `a = 101; ` `    ``int` `b = 102; ` `     `  `    ``if``(check(a, b)) ` `        ``cout << ``"Yes"``; ` `    ``else` `        ``cout << ``"No"``; ` `} ` ` `  `// This code is contributed by ita_c `

## Java

 `// Java implementation of the approach  ` `import` `java.util.*;  ` ` `  `class` `GFG{  ` ` `  `// Function to remove zeroes from a number      ` `public` `static` `int` `remove(``int` `x)  ` `{  ` `     `  `    ``// Converting x into a string  ` `    ``String y = String.valueOf(x);  ` `     `  `    ``// To store the new integer without 0s  ` `    ``String num = ``""``;  ` `    ``int` `i;  ` `     `  `    ``for``(i = ``0``; i < y.length(); i++)  ` `    ``{  ` `        `  `       ``// Skip if current character is 0  ` `       ``if``(y.charAt(i) == ``0``) ` `          ``continue``;  ` `       ``num += y.charAt(i);  ` `    ``}  ` `         `  `    ``// Return the integer after ` `    ``// removing 0s  ` `    ``return` `Integer.parseInt(num);  ` `} ` ` `  ` `  `// Function that returns true if  ` `// the given condition is satisfied  ` `public` `static` `boolean` `check(``int` `a, ``int` `b)  ` `{  ` `     `  `    ``// Calculate c  ` `    ``int` `c = a + b;  ` `     `  `    ``// Remove 0s from a, b and c  ` `    ``a = remove(a);  ` `    ``b = remove(b);  ` `    ``c = remove(c);  ` `     `  `    ``// Check if the equation is  ` `    ``// still correct  ` `    ``if``((a + b) == c)  ` `        ``return` `true``;  ` `    ``else` `        ``return` `false``;  ` `}  ` ` `  `// Driver code  ` `public` `static` `void` `main(String[] args)  ` `{  ` `    ``int` `a = ``101``;  ` `    ``int` `b = ``102``;  ` `     `  `    ``if``(check(a, b))  ` `        ``System.out.println(``"Yes"``); ` `    ``else` `        ``System.out.println(``"No"``);  ` `}  ` `}  ` ` `  `// This code is contributed by grandmaster  `

## Python3

 `# Python3 implementation of the approach ` ` `  `# Function that returns true if  ` `# the given condition is satisfied ` `def` `check(a, b): ` `     `  `    ``# Calculate c ` `    ``c ``=` `a ``+` `b ` `     `  `    ``# Remove 0s from a, b and c ` `    ``a ``=` `remove(a) ` `    ``b ``=` `remove(b) ` `    ``c ``=` `remove(c) ` `     `  `    ``# Check if the equation is still correct ` `    ``if``((a ``+` `b) ``=``=` `c): ` `        ``return` `True` `    ``else``: ` `        ``return` `False` ` `  `# Function to remove zeroes from a number ` `def` `remove(x): ` `     `  `    ``# Converting x into a string ` `    ``y ``=` `str``(x) ` `     `  `    ``# To store the new integer without 0s ` `    ``num ``=` `"" ` `    ``for` `i ``in` `range``(``len``(y)): ` `         `  `        ``# Skip if current character is 0 ` `        ``if``(y[i] ``=``=` `"0"``): ` `            ``continue` `        ``num ``+``=` `y[i] ` `         `  `    ``# Return the integer after removing 0s ` `    ``return` `int``(num) ` ` `  `# Driver code ` `a ``=` `101` `b ``=` `102` ` `  `if``(check(a, b)): ` `    ``print``(``"Yes"``) ` `else``: ` `    ``print``(``"No"``) `

## PHP

 ` `

Output:

```Yes
```

Alternate implementation in Python:

## Python3

 `# Python3 implementation of the approach ` `  `  `# Calculate the sum with Zero's intact ` `d``=``a``+``b ` `  `  `# Then convert the numbers to string  ` `# replace '0' with '' (blank) ` `  `  `a``=``str``(a).replace(``'0'``,'') ` `b``=``str``(b).replace(``'0'``,'') ` `  `  `# Now convert the strings back to numbers ` `# Add the numbers ` `c``=``int``(a)``+``int``(b) ` `  `  `if` `c``=``=``d: ` `    ``print``(``'Yes'``) ` `else``: ` `    ``print``(``'No'``)  ` `  `  `# This code is contributed by Sandeep Midde `

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.