sqrt function not defined in the math.h header?
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
im having the same issue,
#include <stdio.h>
#include <math.h>
int main(void) {
float x1=0.0,x2=0.0,a,b,c,delta=0.0,Rdelta=0.0;
printf("a:");
scanf("%f",&a);
printf("b:");
scanf("%f",&b);
printf("c:");
scanf("%f",&c);
delta=(powf(b,2))-4ac;
printf("delta:%lf",delta);
Rdelta=(powf(delta,0.5));
x1=(-b-Rdelta)/2a;
x2=(-b+Rdelta)/2a;
printf("x1:%f",x1);
printf("x2:%f",x2);
return 0;
}
in my code you can change 'Rdelta=(powf(delta,0.5));' for 'Rdelta=(sqrtf(delta));' and it still inst going to work
So, math.h functions are not available in Replit?
I don't know why it doesn't work, but try removing the
sqrt()
and replace it with the value to 0.5 powersqrt(x) equals x^0.5
@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.