#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
float f (float x)
{
float A;
a=x*x*x-2*x-5;
return A;
}
/*
Www.quzhuanpan.com
Reprint please be sure to inform
*/
int main (void)
{
Double low,bottom,prec,mid;//left endpoint, right endpoint, precision, middle value
CLRSCR ();
printf ("\nplease input data low=");
scanf ("%lf", &low);
printf ("\nplease input data bottom=");
scanf ("%lf", &bottom);
printf ("\nplease input data precision=");
scanf ("%lf", &prec);
Mid= (Low+bottom)/2;
if (f (Low) *f (bottom) <0)
{
while (f (mid)!=0)
{
Mid= (Low+bottom)/2;
if (f (Mid) *f (low) <0)
{
Bottom=mid;
if (Fabs (bottom-low) <prec)
{
Break
}
Else
Continue
}
Else
{
Low=mid;
if (Fabs (bottom-low) <prec)
{
Break
}
Else
Continue
}
}
printf ("\ n");
Mid= (Low+bottom)/2;
printf ("The root of f (x) =0 is x=%lf\n", mid);
}
Else
{
printf ("NO root! Refresh input\n ");
}
return 0;
}
Real roots of nonlinear equation by dichotomy method