# The third root of a number

• 08-24-2005
dwks
The third root of a number
I was wondering how to calculate the third square root of a number. Or the nth square root of a number. Is there a function for it?

I know you can calculate the fourth square root like this:
Code:

```#include <math.h> sqrt(sqrt(81));```
But that only works for multiples of two.
• 08-24-2005
Dave_Sinkula
I don't know if I understand what you mean by "third" and "fourth" square root. If you just mean the third root, 4th root, nth root, then I'd say use pow.
Code:

`pow(x, 1.0 / n);`
• 08-24-2005
ILoveVectors
he means, the cubed root, (when he talking about third)

8 * 8 * 8 = 512 // he want to know how to find the 8

3 * 3 * 3 = 27 // he want to know how to find the 3

or if this came up

5 * 5 * 5 * 5 = 625 // he want to know how to find the 5
• 08-24-2005
Tonto
Of course he does. And of course, square roots, cube roots, etc. are really just fractional exponents. Thus:

Code:

```#include <math.h> #include <stdio.h> int main () {         printf("%2.2f", pow(125, 1.0 / 3.0));         return 0; }```
Retuns a clean 5.
• 08-25-2005
grumpy
An alternative, which has both advantages and disadvantages over using pow(), is

Code:

```#include <math.h> #include <stdio.h> int main () {       double x = 125.0;       int n;         printf("%2.2f", exp(log(x)/n));  /* x an n must both be positive */         return 0; }```
• 08-25-2005
dwks
Okay, thanks. I don't know why I never thought of the pow() version . . . .