#include <cmath>
float pow(float base, float exponent)
base
and exponent
parameters
// 3000 invested at 7% compounded continuously for 5 years float amount{3000}; float interestRate{0.07} float time{5} float finalAmount{0}; float exponent{0}; exponent = interestRate * time; finalAmount = amount * pow(M_E, exponent);
M_E
comes from cmath
and is $e$
M_E
and exponent
are called arguments.
abs
and fabs
and labs
sin
, cos
...
M_PI
is defined in cmath.
sqrt
The factorial of a number n, (written n!) is the number times the factorial of itself minus one. This self-referential definition is easier to understand through an example: The factorial of 2 is 2 * 1; the factorial of 3 is 3 * 2 * 1; the factorial of 4 is 4 * 3 * 2 * 1; and so on. Factorials grow very large, very quickly. An approximation to the factorial for larger values is given by Stirling's formula: $$n! = e^{-n}n^n\sqrt{2\pi n}$$ Theexp
function in the<cmath>
header file gives the value of $e$ raised to a given power. Write a c++ program that computes the factorial of 15 both directly and with Stirling's formula, and outputs both results, together with their difference. You will need to use thedouble
type for this computation.