C++ Program to Check if Given Number is Perfect Square or Not

Write C++ Program to Check if Given Number is Perfect Square or Not

//Write C Program to Check if  Given Number is Perfect Square or Not

#include <iostream>
#include <math.h>

using namespace std;

int main()
{
	int n;

	cout << "Enter the number :--> ";
	cin >> n;

	if(pow((int)sqrt(n), 2) == n)
	{
		cout << "Perfect Square ";
	}
	else
	{
		cout << "Not a perfect square";
	}
	return 0;
}

Output:

Run 1:
Enter the number :--> 4
Perfect Square

Run 2:
Enter the number :--> 89
Not a perfect square

≪ Previous | Next ≫