I have this simple function that finds hypotenuse by given 2 sides in right triangle. I INCLUDED math.h.
#include <stdio.h>
#include <math.h>
double findHypotenuse(int a, int b)
{
return sqrt(pow(a, 2) - pow(b, 2));
}
int main()
{
int a, b;
printf("Enter first side: ");
scanf("%d", &a);
printf("Enter second side: ");
scanf("%d", &b);
printf("The hypotenuse in triangle with a = %d, b = %d equals %lf", a, b, findHypotenuse(a, b));
return 0;
}
But, when i try to compile it(gcc main.c -o main), it returns this:
/usr/bin/ld: /tmp/ccpFqF8U.o: in function findHypotenuse': main.c:(.text+0x33): undefined reference to
pow’
/usr/bin/ld: main.c:(.text+0x5c): undefined reference to pow' /usr/bin/ld: main.c:(.text+0x74): undefined reference to
sqrt’
collect2: error: ld returned 1 exit status
So, what am i doing wrong here?
Иванов Леонид is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1