PROGRAM (TO FIND APPROXIMATE ROOT OF A LINEAR EQUATION BY BISECTION METHOD)

PROGRAM
FINDING APPROXIMATE ROOT OF A LINEAR EQUATION BY BISECTION

#include<stdio.h>
#include<math.h>
#include<conio.h>
float f(float x)
{
 return (x*x*x)-4*x-9;
}

int main()
{
 float x0,x1,a,b;
 int i=1,n;
 clrscr();
 printf("\nenter the values of a, b and max no. of iterations\n");
 scanf("%f %f %d",&a,&b,&n);
 x0=(a+b)/2;
 printf("\nat iteration %d, root is x= %f\n",i,x0);
 i++;
 while(i<=n)
 {
  if(f(a)*f(x0)<0)
  b=x0;
  else
  a=x0;
  x1=(a+b)/2;
  printf("at intersect %d, root is x=%f\n",i,x1);
  if(fabs(x1-x0)<0.001)
  {
   printf("after %d iterations, the value of root is %f\n",i,x1);
   break;
  }
  x0=x1;
  i++;
 }
 getch();
 return 0;

}

OUTPUT:-



Share this

Related Posts

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
:-?
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
$-)
(y)
(f)
x-)
(k)
(h)
cheer
Powered by Blogger.

Popular Posts