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.126742687076

5th root: 3.22549685893672

root to 5th power: 349.126742687076

number: 933.513863012195

5th root: 3.92666773917324

root to 5th power: 933.513863012195

number: 337.094322778285

5th root: 3.20295094809955

root to 5th power: 337.094322778285

number: 921.04862164706

5th root: 3.91612469036527

root to 5th power: 921.04862164706

number: 193.956033326685

5th root: 2.86774584184895

root to 5th power: 193.956033326685

number: 536.526418756694

5th root: 3.51494247913713

root to 5th power: 536.526418756694

number: 769.721171818674

5th root: 3.77804117237769

root to 5th power: 769.721171818674

number: 245.490406174213

5th root: 3.00612409691297

root to 5th power: 245.490406174213

number: 818.889678921551

5th root: 3.82512013459173

root to 5th power: 818.889678921551

number: 422.267477028072

5th root: 3.35056098160768

root to 5th power: 422.267477028072

--

Martin Ambuhl