# Program to check Plus Perfect Number

Given a ‘n’ digit number x, check if it is a plus perfect number or not. A number is plus perfect number if it is equal to the sum of its digits raised to the nth power.

Examples :

```Input : x  = 371
Output : Yes
Explanation :
Number of digits n = 3
(3*3*3) + (7*7*7) + (1*1*1) = 371

Input : x = 9474
Output : Yes
Explanation :
Number of digits n = 4
(9*9*9*9) + (4*4*4*4) + (7*7*7*7) +
(4*4*4*4) = 9474

Input : x = 9473
Output : No
Explanation :
Number of digits n = 4
(9*9*9*9) + (4*4*4*4) + (7*7*7*7) +
(3*3*3*3) != 9474
```

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

Below is the implementation to check if a number is plus perfect number or not.

## C++

 `// CPP implementation to check ` `// if the number is plus perfect  ` `// or not ` `#include ` `using` `namespace` `std; ` ` `  `// function to check plus perfect number ` `bool` `checkplusperfect(``int` `x) ` `{ ` `    ``int` `temp = x; ` `     `  `    ``// calculating number of digits ` `    ``int` `n = 0; ` `    ``while` `(x != 0) { ` `        ``x /= 10; ` `        ``n++; ` `    ``}    ` `     `  `    ``// calculating plus perfect number ` `    ``x = temp; ` `    ``int` `sum = 0; ` `    ``while` `(x != 0) { ` `        ``sum += ``pow``(x % 10, n); ` `        ``x /= 10; ` `    ``} ` `     `  `    ``// checking whether number  ` `    ``// is plus perfect or not ` `    ``return` `(sum == temp); ` `} ` ` `  `// driver program ` `int` `main() ` `{     ` `    ``int` `x = 9474; ` `    ``if` `(checkplusperfect(x)) ` `        ``cout << ``"Yes"``; ` `    ``else` `        ``cout << ``"No"``;         ` `    ``return` `0; ` `}  `

## Java

 `// java implementation to check ` `// if the number is plus perfect  ` `// or not ` `import` `java.io.*; ` ` `  `class` `GFG { ` `     `  `    ``// function to check plus perfect number ` `    ``static` `boolean` `checkplusperfect(``int` `x) ` `    ``{ ` `        ``int` `temp = x; ` `         `  `        ``// calculating number of digits ` `        ``int` `n = ``0``; ` `        ``while` `(x != ``0``)  ` `        ``{ ` `            ``x /= ``10``; ` `            ``n++; ` `        ``}  ` `         `  `        ``// calculating plus perfect number ` `        ``x = temp; ` `        ``int` `sum = ``0``; ` `        ``while` `(x != ``0``)  ` `        ``{ ` `            ``sum += Math.pow(x % ``10``, n); ` `            ``x /= ``10``; ` `        ``} ` `         `  `        ``// checking whether number  ` `        ``// is plus perfect or not ` `        ``return` `(sum == temp); ` `    ``} ` `     `  `    ``// Driver program ` `    ``public` `static` `void` `main (String[] args)  ` `    ``{ ` `        ``int` `x = ``9474``; ` `        ``if` `(checkplusperfect(x)) ` `            ``System.out.println ( ``"Yes"``); ` `        ``else` `            ``System.out.println ( ``"No"``);  ` `     `  `    ``} ` `} ` ` `  `// This code is contributed by vt_m `

## Python3

 `# Python 3 implementation to check ` `# if the number is plus perfect  ` `# or not ` `import` `math ` ` `  `# function to check plus perfect number ` `def` `checkplusperfect(x) : ` `    ``temp ``=` `x ` `     `  `    ``# calculating number of digits ` `    ``n ``=` `0` `    ``while` `(x !``=` `0``) : ` `        ``x ``=` `x ``/``/` `10` `        ``n ``=` `n ``+` `1` `     `  `     `  `    ``# calculating plus perfect number ` `    ``x ``=` `temp ` `    ``sm ``=` `0` `    ``while` `(x !``=` `0``) : ` `        ``sm ``=` `sm ``+` `(``int``)(math.``pow``(x ``%` `10``, n)) ` `        ``x ``=` `x ``/``/` `10` `     `  `     `  `    ``# checking whether number  ` `    ``# is plus perfect or not ` `    ``return` `(sm ``=``=` `temp) ` ` `  ` `  `# driver program ` `x ``=` `9474` `if` `(checkplusperfect(x)) : ` `    ``print``(``"Yes"``) ` `else` `: ` `    ``print``(``"No"``) ` `     `  ` `  `# This code is contributed by Nikita Tiwari. `

## C#

 `// C# implementation to check ` `// if the number is plus perfect  ` `// or not ` `using` `System; ` ` `  `class` `GFG { ` `     `  `    ``// function to check plus perfect number ` `    ``static` `bool` `checkplusperfect(``int` `x) ` `    ``{ ` `        ``int` `temp = x; ` `         `  `        ``// calculating number of digits ` `        ``int` `n = 0; ` `        ``while` `(x != 0)  ` `        ``{ ` `            ``x /= 10; ` `            ``n++; ` `        ``}  ` `         `  `        ``// calculating plus perfect number ` `        ``x = temp; ` `        ``int` `sum = 0; ` `        ``while` `(x != 0)  ` `        ``{ ` `            ``sum += (``int``)Math.Pow(x % 10, n); ` `            ``x /= 10; ` `        ``} ` `         `  `        ``// checking whether number  ` `        ``// is plus perfect or not ` `        ``return` `(sum == temp); ` `    ``} ` `     `  `    ``// Driver program ` `    ``public` `static` `void` `Main ()  ` `    ``{ ` `        ``int` `x = 9474; ` `        ``if` `(checkplusperfect(x)) ` `            ``Console.WriteLine ( ``"Yes"``); ` `        ``else` `            ``Console.WriteLine ( ``"No"``);  ` `     `  `    ``} ` `} ` ` `  `// This code is contributed by vt_m `

## PHP

 ` `

Output :

```Yes
```

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

My Personal Notes arrow_drop_up

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.

Improved By : jit_t

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.