Write a C++ program to find Square Root of a Number

By | 25.12.2016

Square Root of a Number


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 .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

5 2 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
ali

astrolop