/*CSEMATTER.BLOGSPOT.IN
program to find root by regula falsi method*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define f(x) (x*x*x-2*x-5)
void main()
{
int a,b;
float e,f,c,d,itr=0,maxitr=8;
clrscr();
printf("enter the values of intervals");
scanf("%d %d",&a,&b);
e=b-a;
f=f(b)-f(a);
c=a-((e/f) *f(a));
do
{
if(f(a)*f(c)<0)
{ b=c;}
else a=c;
d=a-((e/f) *f(a));
if (fabs(d-c)<0.0001)
{printf("%f is the root",d);
exit(0);}
else
c=d;
itr++;}
while(itr<maxitr);
if(itr>maxitr)
printf("sol doesntconverge no. of iteratn not sufficient");
getch();}
/*output
enter the values of intervals 2 3
2.05882 is the root
*/
program to find root by regula falsi method*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define f(x) (x*x*x-2*x-5)
void main()
{
int a,b;
float e,f,c,d,itr=0,maxitr=8;
clrscr();
printf("enter the values of intervals");
scanf("%d %d",&a,&b);
e=b-a;
f=f(b)-f(a);
c=a-((e/f) *f(a));
do
{
if(f(a)*f(c)<0)
{ b=c;}
else a=c;
d=a-((e/f) *f(a));
if (fabs(d-c)<0.0001)
{printf("%f is the root",d);
exit(0);}
else
c=d;
itr++;}
while(itr<maxitr);
if(itr>maxitr)
printf("sol doesntconverge no. of iteratn not sufficient");
getch();}
/*output
enter the values of intervals 2 3
2.05882 is the root
*/
No comments:
Post a Comment