#include <stdio.h>
#include <math.h>
#define E 1E-3
long double Fun(long double x);
int main() {
long double a = 0;
long double b = 1;
long double temp;
while(fabsl(a - b) > E){
temp = a + b;
temp = temp / 2;
long double Funa = Fun(a);
long double Funb = Fun(b);
long double Funtemp = Fun(temp);
if(Funtemp == 0){
printf("temp = %Lf\n",temp);
break;
}
if(Funtemp * Funa < 0){
a = temp;
}
else if(Funtemp * Funb < 0) {
b = temp;
}
}
printf("a = %Lf\nb = %Lf", a, b);
return 0;
}
long double Fun(long double x){
return x*x*x + x*x - 1;
}
I don't know why the Fun() has segmentation fault? Really confused.
here are the information reported by clion below:
clion:
Fun(a) = -var-create: unable to create variable object
Signal = SIGSEGV (Segmentation fault)