We need to check whether a number is perfect square or not without finding its square root.

Input : n = 36
Output : Yes

Input : n = 12
Output : No

We have discussed a method to check if a number is perfect square.

The idea is to run a loop from i = 1 to floor(sqrt(n)) then check if squaring it makes n.

#include <bits/stdc++.h>

using namespace std;

  

bool isPerfectSquare(int n)

{

    int i;

    for (i = 1; i * i < n; i++)

        ;

  

    return (i * i == n);

}

  

int main()

{

    int n = 36;

    if (isPerfectSquare(n))

        cout << "Yes";

    else

        cout << "No";

  

    return 0;

}



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.