Using pow Function in C: Here's How + Troubleshooting

  • Thread starter Thread starter tandoorichicken
  • Start date Start date
  • Tags Tags
    Function
AI Thread Summary
The pow function from math.h is used to calculate powers, with the syntax pow(a, b) representing a raised to the power of b. The provided code snippet for calculating monthly payments appears correct, but issues may arise if the proper compiler options are not used. When compiling with gcc, it's essential to include the -lm option to link the math library and ensure math.h is included in the code. Testing the program with these adjustments should resolve any compilation errors. Proper usage of the pow function is crucial for accurate calculations in C programming.
tandoorichicken
Messages
245
Reaction score
0
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.
 
Physics news on Phys.org
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.
 
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
 
Thread 'Variable mass system : water sprayed into a moving container'
Starting with the mass considerations #m(t)# is mass of water #M_{c}# mass of container and #M(t)# mass of total system $$M(t) = M_{C} + m(t)$$ $$\Rightarrow \frac{dM(t)}{dt} = \frac{dm(t)}{dt}$$ $$P_i = Mv + u \, dm$$ $$P_f = (M + dm)(v + dv)$$ $$\Delta P = M \, dv + (v - u) \, dm$$ $$F = \frac{dP}{dt} = M \frac{dv}{dt} + (v - u) \frac{dm}{dt}$$ $$F = u \frac{dm}{dt} = \rho A u^2$$ from conservation of momentum , the cannon recoils with the same force which it applies. $$\quad \frac{dm}{dt}...
Back
Top