/ * The program is find the root of Algebraic and Transcendental Equations by Iteration Method */
#include<stdio.h>
#include<math.h>
float root (float x)
{
float f;
f = sin (x)–10*x +10;
return (f) ;
}
float ite (float x)
{
float g;
g=1+ sin (x)/10;
return (g);
}
void main()
{
int i, n;
float a,b,x,e,t;
printf(“ Type a \n”) ;
scanf(“%f ”, &a );
printf( “ Type maximum no iteration\n”);
scanf (“%d”, &n);
printf( “ Type the value of e \n”);
scanf (“%f”, &e);
i = 1; t =1;
while (t>e && i<=n)
{
x = ite (a) ;
t = fabs (x-a) ;
a = 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();
return 0 ;
}
No comments:
Post a Comment