Home Basic Loop Array string Function Pointer Contact STUDY

# AHF    C    PROGRAM    SOLVING

### Roots using False Position method

```
// AHF C PROGRAM SOLVING

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define pf printf
int main()
{
float x1=0.0,x2=2.0,value_x1,value_x2,mid_point=0.0,value_mid_point,error,divide,mul;
pf("\nEnter the error: ");
scanf("%f",&error);
repeat_again:
value_x1=(1 * pow(x1,2)) - (1  * x1 ) - 2;
value_x2=(1 * pow(x2,2)) - (1  * x2 ) - 2;
divide=(x2 - x1)/(value_x2 - value_x1);
mul=(value_x1 * divide);
mid_point= (x1 - mul);
value_mid_point=(1 * pow(mid_point,2)) - (1  * mid_point ) - 2;
if(value_x1 * value_x2 > 0 || value_x1 * value_mid_point == 0)
{
pf("\nno root");
goto end;
}

if(value_x1 * value_mid_point < 0)
x2=mid_point;
else
x1=mid_point;
//below line showing operation into repeat_again statement label
//pf("\nmid_point: %f\nv_x1: %f\nv_x2: %f\nv_m: %f\nx1: %f\nx2: %f\na-v: %f\n\n\n",mid_point,value_x1,value_x2,value_mid_point,x1,x2,((x2-x1)/x2));
if(((x2-x1)/x2)<error)
{
pf("\nThe root is: %f",((x1+x2)/2.0));
goto end;
}
else
goto repeat_again;

end:
exit(1);
}

```
OUTPUT: