Replacement pow() function

From Programming In C

Exercise 5.1

Write a function that provides an alternative to the pow() function provided by math.h. Your function should be able to detect whether the exponent is a positive integer or not. For positive integers less than 20 the function should calculate the correct power using direct multiplication. Otherwise the function should use the pow() function.

The prototype for your function should be:

  double pow_new(double x, double exponent);

Hint: any integer value sent as an exponent to this function will be changed to a double type with a zero after the decimal point.

Write a program that demonstrates your function working.


Next exercise

Return to the course summary

phy225: Course Details

general


compilers


2011-12 assessments


past exam papers

  • 2008-9 (http://physics-database.group.shef.ac.uk/exampapers/2008-09/PHY225%20LT.pdf)
  • 2009-10 (http://physics-database.group.shef.ac.uk/exampapers/2009-10/PHY225%20Exam%20Sem%201%202009-10.pdf)
  • 2010-11 (http://physics-database.group.shef.ac.uk/exampapers/2010-11/PHY225_10_11.pdf)