Home >Backend Development >C++ >What is the ten's complement of a decimal number?
9's complement and 10's complement are used to make arithmetic operations in number systems easier. These are used to make computational operations easier via one's complement implementation and often trade hardware usage to the program.
To get the 9's complement of any number we have to use (10n support> – 1) where n = number of digits in the number, or in a simpler way we have to start with 9 Subtracts each digit of a given decimal number from .
10's complement After finding the 9's complement of the number, it is relatively easy to find the 10's complement. We must add 1 to the 9's complement of any number to obtain the required 10's complement of that number. Alternatively, if we want to find 10's complement directly, we can do it as follows: (10n – number), where n = the number of digits in the number.
Let's take a decimal number 456, the 9's complement of this number will be
999 -456 _____ 543
10's complement of this number
543 (+)1 ______ 544
Input:456 Output:544
Mathematically,
10’s complement = 9’s complement + 1 10’s complement = 10i – num
Where, i = the total number of digits in num.
#include <iostream> #include<math.h> using namespace std; int main() { int i=0,temp,comp,n; n=456; temp = n; while(temp!=0) { i++; temp=temp/10; } comp = pow(10,i) - n; cout<<comp; return 0; }
The above is the detailed content of What is the ten's complement of a decimal number?. For more information, please follow other related articles on the PHP Chinese website!