Find the Square Root of a Number in C++

We can find square root of any number in C++ language. Before that we can see what is square root of a number. Square root of a number x is y when x=y^2. In other words y is a square of x.

There are many ways to find the square root of a number in C++ Language. Here we use the standard function which is normally present in C++ Language to find the square root value.

Sqrt() function is used to find square root of any number in C++ language. This function is defined in math.h header file. This function accepts any number and finds its square root value.

Find the Square Root of a Number in C++

Find the Square Root of a Number in C++

#include<iostream>
#include<math.h>
 
using namespace std;
 
int main()
{
float sq,n;
cout<<"Enter any number:";
cin>>n;
sq=sqrt(n);
cout<<"Square root of "<<n<<" is "<<sq;
return 0;
}

The square root function value is assigned to the variable sq. Finally, the sq value is displayed on the output screen.

Read Also : Armstrong Number in C++

Output

Enter any number: 9

Square root of 9 is 3

Final Words

I hope this article helps you to Find the Square Root of a Number in C++ Program. If you face any issues please let me know via the comment section. Share this article with other C++ program developers via social networks.

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment