how to square a number in c++ code example
Example 1: square c++
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = 10.25, result;
result = sqrt(x);
cout << "Square root of " << x << " is " << result << endl;
return 0;
}
Example 2: how to check sqrt of number is integer c++
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);
}