![]() ![]() | coding-style/indrykning/find-rod/fr13.c - Så bliver det ikke meget værre... | Lektion 6 - slide 16 : 21 Program 10 |
#include <stdio.h> double f (double x); int sameSign(double x, double y); double middleOf(double x, double y); int isSmallNumber(double x); /* Just ugly */ double findRootBetween(double a, double b) { double l = a, u = b ; while (!isSmallNumber(f(middleOf(l, u)))) { if(sameSign(f(middleOf(l, u)), f(u))) u = middleOf(l,u); else l = middleOf(l, u); } return middleOf(l, u); } int main (void) { findRootBetween(-3.0, 5.0);}