# Check whether the number can be made perfect square after adding 1

Given an integer N, the task is to check whether N the given number can be made a perfect square after adding 1 to it.

Examples:

Input: 3
Output: Yes
3 + 1 = 4 which is a perfect square i.e. 22

Input: 5
Output: No
5 + 1 = 6 which is not a perfect square.

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

Approach: Check whether n + 1 is a perfect square or not by taking the square root of n + 1 and checking whether it is an integer. If it is then n + 1 is a perfect square and n is a sunny number.

Below is the implementation of the above approach:

## C++

 `// C++ implementation of the approach ` `#include ` `using` `namespace` `std; ` ` `  `// Function that returns true ` `// if x is a perfect square ` `bool` `isPerfectSquare(``long` `double` `x) ` `{ ` ` `  `    ``// Find floating point value of ` `    ``// square root of x ` `    ``long` `double` `sr = ``sqrt``(x); ` ` `  `    ``// If square root is an integer ` `    ``return` `((sr - ``floor``(sr)) == 0); ` `} ` ` `  `// Function that returns true ` `// if n is a sunny number ` `bool` `isSunnyNum(``int` `n) ` `{ ` ` `  `    ``// If (n + 1) is a perfect square ` `    ``if` `(isPerfectSquare(n + 1)) ` `        ``return` `true``; ` `    ``return` `false``; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``int` `n = 3; ` ` `  `    ``if` `(isSunnyNum(n)) ` `        ``cout << ``"Yes"``; ` `    ``else` `        ``cout << ``"No"``; ` ` `  `    ``return` `0; ` `} `

## Java

 `// Java implementation of the approach  ` ` `  `class` `GFG  ` `{ ` `     `  `    ``// Function that returns true  ` `    ``// if x is a perfect square  ` `    ``static` `boolean` `isPerfectSquare(``double` `x)  ` `    ``{  ` `     `  `        ``// Find floating point value of  ` `        ``// square root of x  ` `        ``double` `sr = Math.sqrt(x);  ` `     `  `        ``// If square root is an integer  ` `        ``return` `((sr - Math.floor(sr)) == ``0``);  ` `    ``}  ` `     `  `    ``// Function that returns true  ` `    ``// if n is a sunny number  ` `    ``static` `boolean` `isSunnyNum(``int` `n)  ` `    ``{  ` `     `  `        ``// If (n + 1) is a perfect square  ` `        ``if` `(isPerfectSquare(n + ``1``))  ` `            ``return` `true``;  ` `        ``return` `false``;  ` `    ``}  ` `     `  `    ``// Driver code  ` `    ``public` `static` `void` `main (String[] args) ` `    ``{  ` `        ``int` `n = ``3``;  ` `     `  `        ``if` `(isSunnyNum(n))  ` `            ``System.out.println(``"Yes"``);  ` `        ``else` `            ``System.out.println(``"No"``);  ` `     `  `    ``}  ` `} ` ` `  `// This code is contributed by Ryuga `

## Python3

 `# Python3 implementation of the approach ` `import` `math as mt ` ` `  `# Function that returns true ` `# if x is a perfect square ` `def` `isPerfectSquare(x): ` ` `  `    ``# Find floating po value of ` `    ``# square root of x ` `    ``sr ``=` `mt.sqrt(x) ` ` `  `    ``# If square root is an eger ` `    ``return` `((sr ``-` `mt.floor(sr)) ``=``=` `0``) ` ` `  `# Function that returns true ` `# if n is a sunny number ` `def` `isSunnyNum(n): ` ` `  `    ``# If (n + 1) is a perfect square ` `    ``if` `(isPerfectSquare(n ``+` `1``)): ` `        ``return` `True` `    ``return` `False` ` `  `# Driver code ` `n ``=` `3` ` `  `if` `(isSunnyNum(n)): ` `    ``print``(``"Yes"``) ` `else``: ` `    ``print``(``"No"``) ` ` `  `# This code is contributed  ` `# by Mohit Kumar `

## C#

 `// C# implementation of the approach  ` `using` `System; ` `class` `GFG  ` `{ ` `     `  `    ``// Function that returns true  ` `    ``// if x is a perfect square  ` `    ``static` `bool` `isPerfectSquare(``double` `x)  ` `    ``{  ` `     `  `        ``// Find floating point value of  ` `        ``// square root of x  ` `        ``double` `sr = Math.Sqrt(x);  ` `     `  `        ``// If square root is an integer  ` `        ``return` `((sr - Math.Floor(sr)) == 0);  ` `    ``}  ` `     `  `    ``// Function that returns true  ` `    ``// if n is a sunny number  ` `    ``static` `bool` `isSunnyNum(``int` `n)  ` `    ``{  ` `     `  `        ``// If (n + 1) is a perfect square  ` `        ``if` `(isPerfectSquare(n + 1))  ` `            ``return` `true``;  ` `        ``return` `false``;  ` `    ``}  ` `     `  `    ``// Driver code  ` `    ``public` `static` `void` `Main () ` `    ``{  ` `        ``int` `n = 3;  ` `     `  `        ``if` `(isSunnyNum(n))  ` `            ``Console.WriteLine(``"Yes"``);  ` `        ``else` `            ``Console.WriteLine(``"No"``);  ` `    ``}  ` `} ` ` `  `// This code is contributed by Code_Mech. `

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

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.