#include<stdio.h>
#include<math.h>
#include<conio.h>
#define f(x) x*x-6*x+3
#define E 0.0001
void main()
{
float x1,x2,f1,f2 xm,fm;
int n=1;
clrscr();
a1:
printf("enter the initial value\n");
scanf("%f %f,&x1,&x2);
f1=f(x1);
f2=f(x2);
if((f1*f2)>0)
{
pirntf("\n please,try once again:\n");
goto a1;
}
a3:
xm=(x1+x2)/2;
printf("\n iteration %d",n);
n=n+1;
printf("%f",xm);
fm=f(xm);
if(fm==0)
{
printf("\n the required root is:%f”,xm);
goto a2;
}
else if(f1*fm<0)
{
x2=xm;
f2=fm;
}
else
{
x1=xm;
f1=fm;
}
if(fabs(x2-x1)<E)
{
printf("\n the required root is: %f, (x1+x2)/2);
goto a2;
}
else
{
goto a3;
}
a2:
getch();
}
No comments:
Post a Comment