C# Find Nth Root

前端 未结 2 1895
一向
一向 2020-12-08 21:42

I use below method to calculate Nth Root of double value, but it takes a lot of time for calculating the 240th root. I found out about Newton method, but was not able to imp

相关标签:
2条回答
  • static double NthRoot(double A, int N)
    {
        return Math.Pow(A, 1.0 / N);
    }
    

    From Wikipedia:

    In calculus, roots are treated as special cases of exponentiation, where the exponent is a fraction:

    \sqrt[n]{x} \,=\, x^{1/n} 
    
    0 讨论(0)
  • 2020-12-08 22:35

    You can use the same function used to find the power of a number, just use reciprocal of the number instead of the number itself.

    To find N root of X you can write,

    int root = Convert.ToInt32(Math.Pow(X, (1 / N)); 
    
    0 讨论(0)
提交回复
热议问题