#include<stdio.h>
#include<conio.h>
double F(double x)
{
return(x*x*x-x-1);
};
void main()
{
int iter,ctr=1;
double x0,x1,l1,l2,r;
clrscr();
printf("\nEquation is :\n\n\tx^3-x-1");
printf("\nEnter the first approximate value : ");
scanf("%lf",&x0);
printf("\nEnter the second approximate value : ");
scanf("%lf",&x1);
printf("\nEnter the number of itteration : ");
scanf("%d",&iter);
while(ctr<=iter)
{
r=(x0+x1)/2;
printf("\nAfter %d itteration root is : %lf",ctr,r);
l1=F(r);
printf("\t%lf",l1);
l2=F(x0);
if(l1*l2<0)
x1=r;
else
x0=r;
ctr++;
}
printf("\n\nThe approximate root is : %lf",r);
getch();
}
#include<conio.h>
double F(double x)
{
return(x*x*x-x-1);
};
void main()
{
int iter,ctr=1;
double x0,x1,l1,l2,r;
clrscr();
printf("\nEquation is :\n\n\tx^3-x-1");
printf("\nEnter the first approximate value : ");
scanf("%lf",&x0);
printf("\nEnter the second approximate value : ");
scanf("%lf",&x1);
printf("\nEnter the number of itteration : ");
scanf("%d",&iter);
while(ctr<=iter)
{
r=(x0+x1)/2;
printf("\nAfter %d itteration root is : %lf",ctr,r);
l1=F(r);
printf("\t%lf",l1);
l2=F(x0);
if(l1*l2<0)
x1=r;
else
x0=r;
ctr++;
}
printf("\n\nThe approximate root is : %lf",r);
getch();
}
RELATED TOPICS |
---|
A C Program to represent N-R Method. |
A C Program to represent Secant Method. |
No comments:
Post a Comment