# Answer to Question #17392 in C++ for Wayan Lonod

Question #17392

Write a Function in C language that will allow floating point number to be raised to an integer power. (i.e. to calculate y= xn where x, y are floating point variables and n is an integer.

Expert's answer

float power(int pow, float from) // x power y

{

float temp = from;

if(pow > 0)

{

--pow;

for(int i = 0; i < pow; i++) temp *= from;

}

else if(pow < 0)

{

--pow;

for(int i = 0; i > pow; --i) temp /= from;

}

else if (pow == 0) temp = 1;

return temp;

}

{

float temp = from;

if(pow > 0)

{

--pow;

for(int i = 0; i < pow; i++) temp *= from;

}

else if(pow < 0)

{

--pow;

for(int i = 0; i > pow; --i) temp /= from;

}

else if (pow == 0) temp = 1;

return temp;

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment