Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- int bisect(float a, float b, float p);
- int f(float x);
- int main(void)
- {
- float x1, x2;
- float p, ans;
- x1 = 0;
- x2 = 100;
- scanf("%f", &p);
- ans = bisect(x1, x2, p);
- printf("%f", ans);
- return(0);
- }
- int bisect(float a, float b, float p)
- {
- float c;
- c = (a-b)/2;
- if (abs(a-b) > 2*p)
- {
- return(c);
- }
- else if(f(a)*f(c) < 0)
- {
- return(bisect(a,c,p));
- }
- else if(f(b)*f(c) < 0)
- {
- return(bisect(c, b, p));
- }
- else
- printf("midpoint is exacly on the root");
- }
- int f(float x)
- {
- float func;
- func = ((x-sqrt(3))*(x+x+1));
- return(func);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement