-
Sqrt() Function
hi everyone...just wanna say thanks for everyone that help me so far since i'm very new to C.
the problem asked to write a C function name root4() that returns the fourth root of the argument passed to it. in writing root4() use the sqrt() library function.
this is what i came up with and i feel like its wrong...please help..
#include<stdio.h>
#include<math.h>
double sqrt(double num);//function type
int main()
{
double num,total;
total = sqrt(4.0 + 7*3);
printf("\nthe 4th root is %lf", total);
return 0;
}
output:
the 4th root is 5.000000Press any key to continue
-
>>total = sqrt(4.0 + 7*3);
This is
7*3 = 21
4 + 21 = 25
sqrt(25) = 5
[edit]Obvious typo fixed :rolleyes: (thanks ronin)
-
4+21 = 5? Not in my math class. :D
whadda bout
double root4(double argument){ return sqrt(sqrt(argument)); }
-
What about root( double n, double number ) { return pow( number, 1.0 / n ); }
Edit:
Oops. Forgot to use sqrt.
-
For a bit of math to explain the double square root above, incase you need it...
sqr(x)=x^(1/2)
fourth root (x)=x^(1/4)
((x^n)^m)=x^(n*m)
so...
sqr(sqr(x))=(x^(1/2))^(1/2)=x^(1/4)=fourth root (x)