Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- double f(double x){
- return (-2)*x*x*x-x+2;
- }
- double zeroFinder(double min, double max){
- double mid=(max+min)/2.0;
- if (f(mid)<0.000001 && f(mid)>-0.000001){
- return mid;
- } else if (f(mid)>0.000001){
- return zeroFinder(mid, max);
- } else {
- return zeroFinder(min, mid);
- }
- }
- int main(void) {
- printf("%f", zeroFinder(0.0, 2.0));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment