Ok so can someone help me with adding exponants to a caculator
Printable View
Ok so can someone help me with adding exponants to a caculator
how about
double exp (double) from the <math.h> library
that is e to the power of x .
Other functions at
http://www.opengroup.org/onlinepubs/...sh/math.h.html
Just make a loop out of it, something like this:
That will calculate the value Base to the power of Exp, and puts teh calculated value in Result. That doesn't account for exponents that are less than or equal to 0 (5^0 or 5^-24). But you can easily modify the result to get that.Code:int Base = 2, Exp = 5, ctr, Result;
Result = Base;
for (ctr = 0; ctr < Exp; ctr++)
{
Result *= Base;
}
Math.h is a header, not a library. And don't use math.h (it's deprecated).Quote:
Originally Posted by wgdb198
Instead, use cmath and the std namespace.