Kishor wrote:
Hi Friends
Please help me to write a C program to find the 5th (fifth) root of a given number.
Ex:(1) Input : 32
Output : 5th root of 32 is 2
Ex:(1) Input : 243
Output : 5th root of 243 is 3
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <float.h>
inline double root(double x)
{
return pow(x, 0.2);
}
inline double original(double x)
{
return pow(x, 5.);
}
int main(void)
{
size_t pass;
const size_t maxpass = 10;
double x;
const double upperlimit = 1000.;
srand((unsigned ) time(0));
for (pass = 0; pass < maxpass; pass++) {
x = upperlimit * rand() / (1. + RAND_MAX);
printf("number: %.*g\n", DBL_DIG, x);
printf("5th root: %.*g\n", DBL_DIG, x = root(x));
printf("root to 5th power: %.*g\n\n", DBL_DIG, original(x));
}
return 0;
}
number: 349.12674268707 6
5th root: 3.2254968589367 2
root to 5th power: 349.12674268707 6
number: 933.51386301219 5
5th root: 3.9266677391732 4
root to 5th power: 933.51386301219 5
number: 337.09432277828 5
5th root: 3.2029509480995 5
root to 5th power: 337.09432277828 5
number: 921.04862164706
5th root: 3.9161246903652 7
root to 5th power: 921.04862164706
number: 193.95603332668 5
5th root: 2.8677458418489 5
root to 5th power: 193.95603332668 5
number: 536.52641875669 4
5th root: 3.5149424791371 3
root to 5th power: 536.52641875669 4
number: 769.72117181867 4
5th root: 3.7780411723776 9
root to 5th power: 769.72117181867 4
number: 245.49040617421 3
5th root: 3.0061240969129 7
root to 5th power: 245.49040617421 3
number: 818.88967892155 1
5th root: 3.8251201345917 3
root to 5th power: 818.88967892155 1
number: 422.26747702807 2
5th root: 3.3505609816076 8
root to 5th power: 422.26747702807 2
--
Martin Ambuhl