Write a C++ program to find Square Root of a Number. Here’s simple program to find Square Root of a Number using pow( ) function in C++ Programming Language.
For calculate Square Root of a number we multiply number by 0.5 because square root of any number means power of 1/2 and 1/2=0.5.
pow( ) is a predefined function in math.h header file, it is used for calculate power of any number.
And one another method for this program is use sqrt( ) function it is pre-defined in math.h header file.
sqrt() is a predefined function in math.h header file, it is used for calculate square root of any number.
Here is source code of the C++ program to find Square Root of a Number. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.
SOURCE CODE : :
/* C++ program to find Square Root of a Number */
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int num;
double ans;
cout<<"Enter any positive integer :: ";
cin>>num;
ans=pow((double)num,(double)0.5);
cout<<"\nSquare Root of [ "<<num<<" ] is :: "<<ans<<"\n";
return 0;
}
Output : :
/* C++ program to find Square Root of a Number */
Enter any positive integer :: 50
Square Root of [ 50 ] is :: 7.07107
Process returned 0
Above is the source code for C++ program to find Square Root of Number which is successfully compiled and run on Windows System.The Output of the program is shown above .
For calculate Square Root of a number we multiply number by 0.5 because square root of any number means power of 1/2 and 1/2=0.5.
And one another method for this program is use sqrt( ) function it is pre-defined in math.h header file.
Here is source code of the C++ program to find Square Root of a Number. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.
SOURCE CODE : :
Output : :
Above is the source code for C++ program to find Square Root of Number which is successfully compiled and run on Windows System.The Output of the program is shown above .
need an explanation for this answer? contact us directly to get an explanation for this answer