9’s complement of a decimal number is the subtraction of it’s each digits from 9. Like 1’s complement, 9’s complement is used to subtract a number using addition.
For example, let us compute value of “718 – 123” using 9’s complement and addition. We first find 9’s complement of 718 which is 281. Now we add 281 to 123. We get 404. 9’s complement of this is 595 which is equal to “718 – 123”. So we could find subtraction using addition and 9’s complement.
In case while adding a carry is obtained in the end, also known as the end around carry, it should be added to the answer, removing the carry itself. For example, (83-25) , 9’s complement of 25 is 74 and (83+74 = 157). A carry is obtained, now add it to the number 57, (57+1 = 58) which is the answer.
Given a decimal number n, find 9’s complement of the number.
Input : 25 Output : 9's complement is : 74 Input : 345.45 Output : 9's complement is : 654.54
Let the number be stored as string. We traverse digits of number and subtract every digit from 9.
9's complement is : 654.54
This article is contributed by Dibyendu Roy Chaudhuri. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 10's Complement of a decimal number
- 1's and 2's complement of a Binary Number
- Previous number same as 1's complement
- Complement of a number with any base b
- 8085 program to find 1's and 2's complement of 8-bit number
- 8085 program to find 1’s and 2’s complement of 16-bit number
- Check if binary representation of a given number and its complement are anagram
- Interface 8255 with 8085 microprocessor for 1’s and 2’s complement of a number
- What’s difference between 1's Complement and 2's Complement?
- Count number of digits after decimal on dividing a number
- Program to Convert BCD number into Decimal number
- Convert Decimal To Hexa-Decimal including negative numbers
- Exponential notation of a decimal number
- Convert a given Decimal number to its BCD representation
- Program to convert a BCD to Hexa-Decimal Number
- Number of decimal numbers of length k, that are strict monotone
- Check if Decimal representation of an Octal number is divisible by 7
- Number of digits before the decimal point in the division of two numbers
- Program to convert Hexa-Decimal Number to its equivalent BCD
- Converting Decimal Number lying between 1 to 3999 to Roman Numerals