how to make a sqrt in c++ code example

Example 1: sqrt in c++

#include <cmath>
sqrt(x);

Example 2: sqrt cpp

#include <math.h>

//get square root of a number "b"
int main(){
  	int a = 2; //declare number you want to take square root of
  	int sqrtNum = sqrt (a); //assign the sqrt value to a variable
  	cout << sqrtNum << endl;
	return 0;
}

Example 3: sqrt() function in c++

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	double x = 10.25, result;
	result = sqrt(x);
	cout << "Square root of " << x << " is " << result << endl;

	return 0;
}

Tags:

Cpp Example