Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

Comment



Iterative statement



Test expression



Specifer



Header file




Roots using bisector




// 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,value_mid_point,error;
    pf("\nEnter the error: ");
    scanf("%f" ,&error);
    repeat_again:

    value_x1=pow(x1,2) - x1 - 2;
    value_x2=pow(x2,2) - x2 - 2;
    mid_point=((x1+x2)/2.0);
    value_mid_point=(1 * pow(mid_point,2)) - (1  * mid_point ) - 2;
    if(value_x1 * value_x2 > 0)
        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:


© 2018 - All rights reserved