PDA

View Full Version : pow function in C


tandoorichicken
Oct15-04, 05:15 PM
How do you use the pow function from math.h?
Here's how I've been using it and the compiler gives me trouble:
month_pay = price*i*pow(1.0 + i, (double)n);

This is the way it was written on the handout from our professor but he makes a lot of typos, so I want to make sure if this is the right way to use pow or not.

Tide
Oct15-04, 05:54 PM
It shouldn't take more than a minute or two to run a short test program through your compiler to find out!

You should have no problem demonstrating that pow(a, b) is equivalent to a^b.

Spectre5
Oct15-04, 07:15 PM
well, if you are using gcc I believe you must use the -lm option when compiling....AND include math.h

so you must do:
gcc -lm filename.c