# Find the last two missing digits of the given phone number

Given eight digits of a phone number as an integer N, the task is to find the missing last two digits and print the complete number when the last two digits are the sum of given eight digits.

Examples:

Input: N = 98765432
Output: 9876543244

Input: N = 10000000
Output: 1000000001

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

Approach:

• Get the eight digits of the phone number from N one by one using the Modulo 10 operator (%10).
• Add these digits in a variable say sum to get the sum of the eight digits.
• Now, there are two cases:
• If sum < 10 then it is a single digit i.e. insert 0 in the beginning to make it a two digit number without affecting the value.
• Else sum is the number represented by the last two digits.

Below is the implementation of the above approach:

## C++

 `// C++ implementation of the approach ` ` `  `#include ` `using` `namespace` `std; ` ` `  `// Function to find the last two ` `// digits of the number and ` `// print the complete number ` `void` `findPhoneNumber(``int` `n) ` `{ ` ` `  `    ``int` `temp = n; ` `    ``int` `sum; ` ` `  `    ``// Sum of the first eight ` `    ``// digits of the number ` `    ``while` `(temp != 0) { ` `        ``sum += temp % 10; ` `        ``temp = temp / 10; ` `    ``} ` ` `  `    ``// if sum < 10, then the two digits ` `    ``// are '0' and the value of sum ` `    ``if` `(sum < 10) ` `        ``cout << n << ``"0"` `<< sum; ` ` `  `    ``// if sum > 10, then the two digits ` `    ``// are the value of sum ` `    ``else` `        ``cout << n << sum; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``long` `int` `n = 98765432; ` ` `  `    ``findPhoneNumber(n); ` ` `  `    ``return` `0; ` `} `

## Java

 `// Java implementation of the approach ` `class` `GFG ` `{ ` ` `  `// Function to find the last two ` `// digits of the number and ` `// print the complete number ` `static` `void` `findPhoneNumber(``int` `n) ` `{ ` ` `  `    ``int` `temp = n; ` `    ``int` `sum = ``0``; ` ` `  `    ``// Sum of the first eight ` `    ``// digits of the number ` `    ``while` `(temp != ``0``) ` `    ``{ ` `        ``sum += temp % ``10``; ` `        ``temp = temp / ``10``; ` `    ``} ` ` `  `    ``// if sum < 10, then the two digits ` `    ``// are '0' and the value of sum ` `    ``if` `(sum < ``10``) ` `        ``System.out.print(n + ``"0"` `+ sum); ` ` `  `    ``// if sum > 10, then the two digits ` `    ``// are the value of sum ` `    ``else` `        ``System.out.print(n +``""``+ sum); ` `} ` ` `  `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` `    ``int` `n = ``98765432``; ` ` `  `    ``findPhoneNumber(n); ` `} ` `} ` ` `  `// This code is contributed by PrinciRaj1992 `

## Python 3

 `# Python 3 implementation of the approach ` ` `  `# Function to find the last two ` `# digits of the number and ` `# print the complete number ` `def` `findPhoneNumber(n): ` `    ``temp ``=` `n ` `    ``sum` `=` `0` ` `  `    ``# Sum of the first eight ` `    ``# digits of the number ` `    ``while` `(temp !``=` `0``): ` `        ``sum` `+``=` `temp ``%` `10` `        ``temp ``=` `temp ``/``/` `10` ` `  `    ``# if sum < 10, then the two digits ` `    ``# are '0' and the value of sum ` `    ``if` `(``sum` `< ``10``): ` `        ``print``(n,``"0"``,``sum``) ` ` `  `    ``# if sum > 10, then the two digits ` `    ``# are the value of sum ` `    ``else``: ` `        ``n ``=` `str``(n) ` `        ``sum` `=` `str``(``sum``) ` `        ``n ``+``=` `sum` `        ``print``(n) ` ` `  `# Driver code ` `if` `__name__ ``=``=` `'__main__'``: ` `    ``n ``=` `98765432` ` `  `    ``findPhoneNumber(n) ` ` `  `# This code is contributed by Surendra_Gangwar `

## C#

 `// C# implementation of the approach ` `using` `System; ` ` `  `class` `GFG ` `{ ` `     `  `// Function to find the last two ` `// digits of the number and ` `// print the complete number ` `static` `void` `findPhoneNumber(``int` `n) ` `{ ` `    ``int` `temp = n; ` `    ``int` `sum = 0; ` ` `  `    ``// Sum of the first eight ` `    ``// digits of the number ` `    ``while` `(temp != 0) ` `    ``{ ` `        ``sum += temp % 10; ` `        ``temp = temp / 10; ` `    ``} ` ` `  `    ``// if sum < 10, then the two digits ` `    ``// are '0' and the value of sum ` `    ``if` `(sum < 10) ` `        ``Console.Write(n + ``"0"` `+ sum); ` ` `  `    ``// if sum > 10, then the two digits ` `    ``// are the value of sum ` `    ``else` `        ``Console.Write(n + ``""` `+ sum); ` `} ` ` `  `// Driver code ` `static` `public` `void` `Main () ` `{ ` `    ``int` `n = 98765432; ` ` `  `    ``findPhoneNumber(n); ` `} ` `} ` ` `  `// This code is contributed by jit_t `

Output:

```9876543244
```

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.