Calculating the nth Root of a number

I was trying to make a Calculator in the Console.
Now I was thinking of adding the nth-Root of a Number.
I decided to take the input in the form of a Double.
So my question is: how can we calculate the Root of a number?
The power function is pow, so you can use:
double nthRoot=pow(input,1.0/n);
Well square root can be made with sqrt-function in cmath library. http://cplusplus.com/reference/clibrary/cmath/

However if you want make nth root you can use following:
nth root of x is x^(1/n)
Well, I thought of that.
I think I will use it.
But other than that, is there a mathematical way to do so?

EDIT:
That method will not work since I am parsing a string that is Input by the user.
This is the link to my code(it is still incomplete):http://pastebin.com/6GV5wtLy
Last edited on
Can you make it so that instea of getting string you use just cin?
std::cin >> num1 >> expr >> num2;

spacebar between each...
Last edited on
I had made a version like that earlier.
I wanted to do something different from before.
Hence parsing!
Well, as for other methods:
http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
And the more general variant for non-square roots:
http://de.wikipedia.org/wiki/Heron-Verfahren#Verallgemeinerung_des_Verfahrens (for the kth root of a)
Topic archived. No new replies allowed.