December 2005
Beginner to intermediate
618 pages
20h 19m
English
exp
Calculates the natural exponential of a number
#include <math.h> doubleexp( doublex); floatexpf( floatx); long doubleexpl( long doublex);
The return value of the exp() function is e raised to the power of the function’s
argument, or ex, where
e is Euler’s number,
2.718281.... If the result is beyond the range of the function’s
type, a range error occurs.
The natural exponential function exp() is the inverse of the natural
logarithm function, log().
/* Amount owed = principal * e**(interest_rate * time) */
int principal = 10000; // Initial debt is ten thousand dollars.
int balance = 0;
double rate = 0.055; // Interest rate is 5.5% annually.
double time = 1.5; // Period is eighteen months.
balance = principal *exp( rate * time );
printf("Invest %d dollars at %.1f%% compound interest, and "
"in %.1f years you'll have %d dollars.\n",
principal, rate*100.0, time, balance );This code produces the following output:
Invest 10000 dollars at 5.5% compound interest, and in 1.5 years you'll have 10859 dollars.
Read now
Unlock full access