Q:

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

belongs to collection: C++ Number Solved Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Number Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C++ Program to find Cube Root of a Number... >>
<< C++ program to find LCM of two numbers using funct...