C++ Program to find Square Root of a Number

Write a C++ Program to find the Square Root of a Number. In this C++ program, we used the sqrt math function (sqrtResult = sqrt(number)) to get the result.

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
	double number, sqrtResult;
	
	cout << "\nPlease Enter any Number to find Square root =  ";
	cin >> number;
	
	sqrtResult = sqrt(number);
	
	cout << "\nThe Sqauer root of a " << number << " = " << sqrtResult;
	
 	return 0;
}
C++ Program to find Square Root of a Number 1

C++ Program to find Square Root of a Number Example 2

In this C++ code, we used the math pow function to find the square root.

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
	double number, sqrtResult;
	
	cout << "\nPlease Enter any Number to find Square root =  ";
	cin >> number;
	
	sqrtResult = pow(number, 0.5);
	
	cout << "\nThe Sqauer root of a " << number << " = " << sqrtResult;
	
 	return 0;
}
Please Enter any Number to find Square root =  265

The Sqauer root of a 265 = 16.2788