For some reason, I'm not sure what, it isn't showing the approx root, the avg which should be printed as a non-zero floating point is rather giving 0 as it's value at the end, I'm also not sure if fabs is necessary here or not. Please help me out, p.s- my first question here.
// C program for bisection method
#include<stdio.h>
#include<math.h>
#define F(x) (x*x*x-9*x+1)
int main(int argc, char const *argv[])
{
double guess_1, guess_2,func, avg;
printf("Enter values of 1st guess and 2nd guess : "); //assumes the initial 2 values from user
scanf("%lf%lf",&guess_1,&guess_2);
for (int i = 1; fabs(F(avg)) < 0.001; i++)
{
avg=(guess_1+guess_2)/2;
if (F(guess_1)*F(avg)<0)
{
guess_2=avg;
}else
{
guess_1=avg;
}
}
printf("approximate root is : %lf",avg);
return 0;
}