Musterlösungen
Zur Navigation springen
Zur Suche springen
Funktion wurzel[Bearbeiten]
void main() {
print(wurzel(9.1));
}
double abs(double x) => x < 0 ? -x : x;
double wurzel(double a){
var x = a;
var diff = 0.0;
var counter = 10;
do {
final xneu = 1 / 2 * (x + a / x);
diff = abs(x - xneu);
print('x: $x xneu: $xneu $diff');
x = xneu;
} while(diff > a / 1000 && --counter > 0);
return x;
}