difference between <cmath> and <math.h>

Hello,

I'm currently working on my homework assignment. I do not really need help on it because I understand it and i'm watching online tutorials to further enhance my knowledge. But I am still confused on the <cmath> and <math.h> headers.

Basically I have to raise a power. I'm using the volume formula V=pi*r^2*h. I already declared PI using #declare PI 3.141592. But I just learned I cannot simply do (radius)^2 in C++ rather there's a power function pow() I have to do (around those terms not done fully learning it yet).

My question is with what I am doing, what header do I use or does it matter? Also can someone show me a small example of how to successfully raise a power?

Thanks,
Learning Student
Thank you! Both of my questions answered.
math.h is the deprecated C header. cmath is the C++ header. The difference is that cmath puts all the names in the std namespace.

 
std::pow(a,b) // a^b 
Say if I want to do (3/12)^2 where radius =3 so (radius/12)^2 how would I write that?

pow(radius/12, 2);

is that correct?
Last edited on
That looks correct, but note that you could also save yourself the trouble of having to use <cmath> by just doing squared = (radius/12.0)*(radius/12.0) or radius*radius/144.0
Last edited on
Topic archived. No new replies allowed.