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.
Input: N = 98765432
Input: N = 10000000
- 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:
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer Geeks Classes Live