0 Replies - 1473 Views - Last Post: 10 July 2011 - 07:55 PM Rate Topic: -----

#1 stackoverflow   User is offline

  • D.I.C Addict
  • member icon

Reputation: 166
  • View blog
  • Posts: 545
  • Joined: 06-July 11

Iterative power function

Posted 10 July 2011 - 07:55 PM

Description: This function can be used like a normal function. Feel free to add a declaration for type safety-- or add it to your source file as is and use it. Remember it returns a double!This is an alternative power function using an iterative method.
/**
* power - gets the value of a base brought up to a power
* @base: the desired base
* @power: the desired power 
* @return: returns a double representing the base to the power
*/
double power(double base, double power)
{
  double product = 1; 
  while (power--)
    product *= base;
  return product;
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1