79225186

Date: 2024-11-26 03:03:53
Score: 0.5
Natty:
Report link

You can simply use the absolute value of n, then change the sign of the answer based on the original input n.

double myroot(double n, double k)
{
    bool isNegative = n < 0;
    double result = std::pow(abs(n), 1.0 / k);
    
    return isNegative ? result * -1 : result;
}
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Keegan Fisher