开发者

Help with POW function in C++

m having trouble with the pow function. The equation is A=P*((1+R)/T)^T were "^" is to the power of. How would i use the pow function, i only see examples that are 4 to the 5th power, nothing like what i have to开发者_开发知识库 do


it would simply be A = pow((1+R)/T , T) * P;


The C++ function std::pow can be used as follows: if you write

std::pow(base, exponent)

the function computes baseexponent. In your case, because you want to compute

A = P * ((1 + R) / T) ^ T

You might call the function like this:

A = P * std::pow((1 + R) / T, T);

Note that the second argument needn't be a constant; it can be any value that you'd like, even one you don't know until runtime.

Hope this helps!


P * pow((1+R)/T, T)

The second argument is the exponent (power) to raise the first argument to.


Use man pow to see the usage

A = P * pow((1 + R) / T, T)


Either:

A = P * pow ((1 + R) / T, T)

or:

A = pow (P * (1 + R) / T, T)

depending on whether the power should include the multiplication by P or not.

I would suspect the former since exponentiation tends to have a higher priority in maths - i.e., 4x2 is 4(x2), not (4x)2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜