Home > Backend Development > C++ > body text

What is the ten's complement of a decimal number?

王林
Release: 2023-09-13 15:05:07
forward
1489 people have browsed it

What is the tens 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
Copy after login

10's complement of this number

543
(+)1
______
544
Copy after login

Input:456
Output:544
Copy after login

Explanation

Mathematically,

10’s complement = 9’s complement + 1
10’s complement = 10i – num
Copy after login

Where, i = the total number of digits in num.

Example

#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;
}
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template