Wednesday, 17 December 2014

REGULAR FALSI METHOD IN C

Regular Falsi method using c program


#include<stdio.h>
#include<math.h>
#include<conio.h>

float root(float x)
{
float f;
f=x*x*x-x-1;
return(f);
}
void main()
{
int i,n;
float a,b,x,e,t,p;
clrscr();
printf("Type a and b\n");
scanf("%f %f",&a,&b);
printf("Type maximum number of interval n\n");
scanf("%d",&n);
printf("Type the value of e\n");
scanf("%f",&e);
p=root(a)*root(b);
if(p>0)
printf("Root does not lies between a and b");
else
{
i=1;
t=1;
while(t>e && i<=n)
{
x=(a*root(b)-b*root(a))/(root(b)-root(a));
if(root(x)*root(a)>0)
a=x;
else
b=x;
t=fabs(a-b);
if(t>fabs(root(x)))
t=fabs(root(x));
i++;
}
if(i>n)
printf("Iteration does not converge");
else
{
 printf("Approximate root=%8.4f\n",x);
 printf("Number of Iteration=%d\n",i);
}
}
getch();
}

OUTPUT:


No comments:

Post a Comment