C++ program to find Square Root of a Number




In this Example we will learn how to find the square root of a given number using C++.

In the first example we are going to use std::pow function to calculate the square root.

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  int number, result;
  cout <<"Enter any number: ";
  cin >> number;
  result = pow(number, 0.5);
  cout<<"\nSqure of "<<number<<" is: " << result << endl;
}

/*
OUTPUT
Enter any number: 9
Squre of 9 is: 3
*/

Now In the next example we will learn how to find the square root of a given number using std::sqrt function.

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  int number,result;
  cout << "Enter any numberber: ";
  cin >> number;
  result = sqrt(number);
  cout<<"\nSqure of " << number << " is: " <<result;
}

/*
OUTPUT
Enter any numberber: 36
Squre of 36 is: 6

*/

 

 

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*