![]() |
VOOZH | about |
Given a decimal number N. The task is to find 10’s complement of the number N.
Example:
Input : 25 Output : 10's complement is : 75 Input : 456 Output : 10's complement is : 544
10’s complement of a decimal number can be found by adding 1 to the 9's complement of that decimal number. It is just like 2s complement in binary number representation.
Mathematically,
10's complement = 9's complement + 1
For example, let us take a decimal number 456, 9's complement of this number will be 999-456 which will be 543. Now 10s complement will be 543+1=544.
Therefore,
10's complement = 10len - num
Where, len = total number of digits in num.
Below is the program to find 10's complement of a given number:
75 544
Time Complexity: O(logn) where n is the given number
Auxiliary Space: O(1)