C++ Square Root Function

beginner c++11 math

#include <cmath>

The C++ Standard Library provides the sqrt function which takes the square root of its only argument. Cube roots can also be computed with the cbrt function. For example:

#include <cmath>
#include <iostream>

int main() {
  auto result = sqrt(729);

  std::cout << result << "\n";

  auto result2 = cbrt(729); 
  
  std::cout << result2 << "\n";
}
27
9


For more C++ By Example, click here.