Er.Puneet kumar tyagi
AIM :- Write a program for BISECTION METHOD #include<stdio.h> #include #include<math.h> float f(float x) { return((-0.9)*(x*x)+(1.7)*x+2.5); } void main() { float x1,x2,x3,y1,y2,y3; int i,n; clrscr(); printf("\n enter the value of initial guess x1"); scanf("%f", &x1); printf("\n enter the value of another guess x2"); scanf("%f", &x2); printf("\n enter the number of iterations ="); scanf("%d", &n); y1=f(x1); y2=f(x2); while(y1*y2>0) { printf("\n enter the value of x1 again ="); scanf("%f", &x1); printf("\n enter value of x2 again ="); scanf("%f", &x2); y1=f(x1); y2=f(x2); } for(i=1;i<=n;i++) { x3=((x1+x2)/2);
Er.Puneet kumar tyagi
y3=f(x3); if(y1*y3<0) { x2=x3; y2=y3; } else { x1=x3; y1=y3; } } printf("\n the root x3=%f", x3); getch(); }
OUTPUT Enter the value of initial guess x1=2.8 Enter the value of initial guess x2=3 Enter the number of iterations =3 The root x3 =2.875000