Posts

bisection programming using c language

#include<stdio.h> #include<conio.h> #include<math.h> #define e 0.005 float f(float x) { return ((x*x*x)-x-4); } void main() { float x0,x1,m; float f0,f1,fm; int i=0; clrscr(); l1: printf("enter the two valid number=\n"); scanf("%f%f",&x0,&x1); if((f(x0)*f(x1))>0) { printf("sorry the number is not valid.\nPlease try again.\n"); goto l1; } do {   f0=f(x0);   f1=f(x1);   m=(x0+x1)/2;   fm=f(m);   if((f(x0)*f(m))<0)   {   x1=m;   }   else   {   x0=m;   }   i++;   printf("\iteration=%d",i);   printf("\n root is=%f",m); }while(fabs(f(m))>=e); printf("\n\nThe the function is=%f",fm); getch(); }