# Find the Next perfect square greater than a given number

Given a number N, the task is to find the next perfect square greater than N.

Examples:

```Input: N = 6
Output: 9
9 is a greater number than 6 and
is also a perfect square

Input: N = 9
Output: 16

```

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

Approach:

1. Find the square root of given N.
2. Calculate its floor value using floor function in C++.
3. Then add 1 to it.
4. Print square of that number.

Below is the implementation of above approach:

 `// C++ implementation of above approach ` `#include ` `#include ` `using` `namespace` `std; ` ` `  `// Function to find the next perfect square ` `int` `nextPerfectSquare(``int` `N) ` `{ ` `    ``int` `nextN = ``floor``(``sqrt``(N)) + 1; ` ` `  `    ``return` `nextN * nextN; ` `} ` ` `  `// Driver Code ` `int` `main() ` `{ ` `    ``int` `n = 35; ` ` `  `    ``cout << nextPerfectSquare(n); ` `    ``return` `0; ` `} `

 `// Java implementation of above approach ` `import` `java.util.*; ` `import` `java.lang.*; ` `import` `java.io.*; ` ` `  `class` `GFG ` `{ ` `     `  `// Function to find the ` `// next perfect square ` `static` `int` `nextPerfectSquare(``int` `N) ` `{ ` `    ``int` `nextN = (``int``)Math.floor(Math.sqrt(N)) + ``1``; ` ` `  `    ``return` `nextN * nextN; ` `} ` ` `  `// Driver Code ` `public` `static` `void` `main(String args[]) ` `{ ` `    ``int` `n = ``35``; ` ` `  `    ``System.out.println (nextPerfectSquare(n)); ` `} ` `} ` ` `  `// This code is contributed by Subhadeep `

 `# Python3 implementation of above approach ` ` `  `import` `math ` `#Function to find the next perfect square ` ` `  `def` `nextPerfectSquare(N): ` ` `  `    ``nextN ``=` `math.floor(math.sqrt(N)) ``+` `1` ` `  `    ``return` `nextN ``*` `nextN ` ` `  `if` `__name__``=``=``'__main__'``: ` `    ``N ``=` `35` `    ``print``(nextPerfectSquare(N)) ` ` `  `# this code is contributed by Surendra_Gangwar `

 `// C# implementation of above approach ` `using` `System; ` ` `  `class` `GFG ` `{ ` `     `  `// Function to find the ` `// next perfect square ` `static` `int` `nextPerfectSquare(``int` `N) ` `{ ` `    ``int` `nextN = (``int``)Math.Floor(Math.Sqrt(N)) + 1; ` ` `  `    ``return` `nextN * nextN; ` `} ` ` `  `// Driver Code ` `public` `static` `void` `Main() ` `{ ` `    ``int` `n = 35; ` ` `  `    ``Console.WriteLine(nextPerfectSquare(n)); ` `} ` `} ` ` `  `// This code is contributed  ` `// by Shashank `

 ` `

Output:
```36
```

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.

Article Tags :
Practice Tags :