The C++ module cmath provides basic mathematical functions to calculate the square root or to exponentiate a number. The module also offers functions for logarithmic, trigonometric and hyperbolic calculations.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
// power of number
cout << "Pow: " << pow(2, 4) << endl;
// square root
cout << "Sqrt: " << sqrt(25) << endl;
// cubic root
cout << "Cbrt: " << cbrt(125) << endl;
// computes square root of the sum of the squares of two or three given numbers
cout << "Hypot: " << hypot(10, 20) << endl;
return 0;
}
Pow: 16
Sqrt: 5
Cbrt: 5
Hypot: 22.3607