/*PROGRAM TO FIND THE ROOT OF THE EQUATION BY ITERATION METHOD*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return(1/sqrt(1+x));
}
void main()
{
int i,n;
float x0,x1,e;
clrscr();
printf(“Enter he value of x0,n,e:: \n”);
scanf(“%f%d%f”,&x0,&n,&e);
for(i=1;i<=n;i++)
{
x1=f(x0);l
printf(“\n Root is =%f”,x1);
if(fabs(x1-x0/x1)<e)
{
printf(“\n Current root is =%f”,x1);
break;
}
x0=x1;
}
getch();
}
/*
OUTPUT
Enter the value of x0,n,e::
5
8
.005
Root is = 0.408248
Root is = 0.842676
Root is = 0.736674
Root is = 0.758824
Root is = 0.754030
Root is = 0.755060
Root is = 0.754838
Root is = 0.754886
*/
No comments:
Post a Comment