pow() isn't defined

c

Solution

This is a linker failure. You need to link with the math library, specify `-lm` at the end of your compiler command. From man pow:

Link with -lm.

Problem

``` #include <stdio.h> #include <math.h> void main() { int i, diff, sum = 0, num1 = 6, num2 = 2; for(i = 0; i <= 4; i++) { diff = num1 - num2; sum += pow(diff, i); } printf("%d", sum); } ``` Whenever I am trying to execute this program, an error message just pops up saying: In function `main`: undefined reference to `pow`. What am I missing here?

Original source

Related problems