You are on page 1of 2

Er.

Puneet kumar tyagi

AIM :- Write a program for REGULAR FALSI METHOD

#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return(sin(x)-x+2);
}
void main()
{
float x1,x2,x3,y1,y2,y3,acc;
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++)
Er.Puneet kumar tyagi
{
x3=(((x2*y1)-(x1*y2))/(y1-y2));
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


Enter the value of initial guess x2=3
Enter the number of iterations =5
The root x3 =2.554196

You might also like