Skip to content

Instantly share code, notes, and snippets.

@alexesDev
Created December 26, 2012 21:17
Show Gist options
  • Select an option

  • Save alexesDev/4383238 to your computer and use it in GitHub Desktop.

Select an option

Save alexesDev/4383238 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
#include <float.h>
#define EPSILON 0.01
float func(float x)
{
return powf(x, 4) + 5 * x - 7;
}
void main(void)
{
float a = 0 + EPSILON;
float b = FLT_MAX;
float c = 0;
while(fabs(a - b) >= EPSILON)
{
c = (a + b) / 2;
if(func(b) * func(c) < 0)
a = c;
else
b = c;
}
printf("%10.10f\n", c);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment