# 10’s Complement of a decimal number

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
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

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 compliment 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 compliment 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:

## C++

 `// C++ program to find 10's complement ` ` `  `#include ` `#include ` ` `  `using` `namespace` `std; ` ` `  `// Function to find 10's complement ` `int` `complement(``int` `num) ` `{ ` `    ``int` `i,len=0,temp,comp; ` `     `  `    ``// Calculating total digits ` `    ``// in num ` `    ``temp = num; ` `    ``while``(1) ` `    ``{ ` `        ``len++; ` `        ``num=num/10; ` `        ``if``(``abs``(num)==0) ` `            ``break``;         ` `    ``} ` `     `  `    ``// restore num ` `    ``num = temp; ` `     `  `    ``// calculate 10's complement ` `    ``comp = ``pow``(10,len) - num; ` `     `  `    ``return` `comp; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``cout<

## Java

 `// Java program to find 10's complement ` `import` `java.io.*; ` ` `  `class` `GFG  ` `{ ` `// Function to find 10's complement ` `static` `int` `complement(``int` `num) ` `{ ` `    ``int` `i, len = ``0``, temp, comp; ` `     `  `    ``// Calculating total ` `    ``// digits in num ` `    ``temp = num; ` `    ``while``(``true``) ` `    ``{ ` `        ``len++; ` `        ``num = num / ``10``; ` `        ``if``(Math.abs(num) == ``0``) ` `            ``break``;  ` `    ``} ` `     `  `    ``// restore num ` `    ``num = temp; ` `     `  `    ``// calculate 10's complement ` `    ``comp = (``int``)Math.pow(``10``,len) - num; ` `     `  `    ``return` `comp; ` `} ` ` `  `// Driver code ` `public` `static` `void` `main (String[] args)  ` `{ ` `    ``System.out.println(complement(``25``)); ` `     `  `    ``System.out.println(complement(``456``)); ` `} ` `} ` ` `  `// This code is contributed  ` `// by chandan_jnu. `

## Python3

 `# Python3 program to find  ` `# 10's complement ` `import` `math ` ` `  `# Function to find 10's complement ` `def` `complement(num): ` `    ``i ``=` `0``; ` `    ``len` `=` `0``; ` `    ``comp ``=` `0``; ` `     `  `    ``# Calculating total  ` `    ``# digits in num ` `    ``temp ``=` `num; ` `    ``while``(``1``): ` `        ``len` `+``=` `1``; ` `        ``num ``=` `int``(num ``/` `10``); ` `        ``if``(``abs``(num) ``=``=` `0``): ` `            ``break``;  ` `     `  `    ``# restore num ` `    ``num ``=` `temp; ` `     `  `    ``# calculate 10's complement ` `    ``comp ``=` `math.``pow``(``10``, ``len``) ``-` `num; ` `     `  `    ``return` `int``(comp); ` ` `  `# Driver code ` `print``(complement(``25``)); ` `print``(complement(``456``)); ` ` `  `# This code is contributed by mits  `

## C#

 `// C# program to find  ` `// 10's complement ` `using` `System; ` ` `  `class` `GFG  ` `{ ` `// Function to find 10's complement ` `static` `int` `complement(``int` `num) ` `{ ` `    ``int` `len = 0, temp, comp; ` `     `  `    ``// Calculating total ` `    ``// digits in num ` `    ``temp = num; ` `    ``while``(``true``) ` `    ``{ ` `        ``len++; ` `        ``num = num / 10; ` `        ``if``(Math.Abs(num) == 0) ` `            ``break``;  ` `    ``} ` `     `  `    ``// restore num ` `    ``num = temp; ` `     `  `    ``// calculate 10's complement ` `    ``comp = (``int``)Math.Pow(10, len) - num; ` `     `  `    ``return` `comp; ` `} ` ` `  `// Driver code ` `public` `static` `void` `Main ()  ` `{ ` `    ``Console.WriteLine(complement(25)); ` `     `  `    ``Console.WriteLine(complement(456)); ` `} ` `} ` ` `  `// This code is contributed  ` `// by chandan_jnu. `

## PHP

 ` `

Output:

```75
544
```

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.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.