#include<stdio.h>
#include<math.h>
#include<stdlib.h>
float f(float x)
{
return(pow(x,3)-2*x-5);
}
void main()
{
float x,a,b;
printf("Enter two initial guesses a & b : ");
scanf("%f%f",&a,&b);
do
{
if(f(a)==f(b))
{
printf("Denominator is zero");
exit(0);
}
x=(a*f(b)-b*f(a))/(f(b)-f(a));
a=b;
b=x;
}while(fabs(f(x))>0.00005);
printf("Solution = %f, f(x)= %f",x,f(x));
}






0 comments:
Post a Comment