Skip to content
sqrt function not defined in the math.h header?
Profile icon
bvernon2

working a Lab for class including the math.h function but it gives an error when using the sqrt function. the code runs fine in other online compilers, but i prefer to use repl.it

#include <stdio.h>
#include <math.h>

int main ()
{
float baseA, baseB, height, perimeter;
printf("Enter the first base of the trapezoid: \n");
scanf("%f", &baseA);
printf("Enter the second base of the trapezoid: \n");
scanf("%f", &baseB);
printf("Enter the height of the trapezoid: \n");
scanf("%f", &height);
perimeter = sqrt (heightheight + (baseA - baseB)(baseA - baseB));
printf("Perimeter is : %f\n", perimeter);
return 0;
}

it returns error:
exit status 1
/tmp/cc8huUt7.o: In function 'main':
main.c: (.test+0xbd): undefined reference to 'sqrt'
collect2: error: ld returned 1 exit status

You are viewing a single comment. View All
Profile icon
Geocube101

I don't know why it doesn't work, but try removing the sqrt() and replace it with the value to 0.5 power
sqrt(x) equals x^0.5

Profile icon
ijmc

@Geocube101

I'm having the same issue tiht pow() Replit is kinda a POS, I'd sugest using a normal text editor and just copy pasting it into replit.