# Program to check that number is perfect square or not

## Program to check that number is perfect square or not : –

Method 1:-   1. find the square root of the number .

2. multiple the square root two times .

3. check (sq*sq)==number then it is perfect square

4. otherwise not a perfect square

Code  in C++:-

```#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cout<<"Enter a number\n";
cin>>n;

// checking for perfect square
long long sq=sqrt(n);
if(sq*sq==n)
cout<<n<<" is a perfect square"<<endl;
else
cout<<n<<" is not a perfect square"<<endl;
return 0;
}```

Output:-

```Enter a number
6
6 is not a perfect square```

Method 2: –

• in this method we will use the ceil and floor .
• if ceil(sqrt (n))==floor(sqrt(n)) then number is perfect square.

Code in C++:-

```#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cout<<"Enter a number\n";
cin>>n;

// checking for perfect square
double sq=sqrt(n);
cout<<sq<<endl;
if(ceil(sq)==floor(sq))
cout<<n<<" is a perfect square"<<endl;
else
cout<<n<<" is not a perfect square"<<endl;
return 0;
}```

python code:-

```import math
n=int(input())
x=int(math.sqrt(n))
if (x*x)==n:
print(n,"is a perfect square")
else:
print(n,"is not a perfect square")
```

output:-

```49
49 is a perfect square```

Program to check that number is perfect square or not