Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Programm: one.C // Berechnet etwas umstaendlich die Zahl eins. // // ACHTUNG: Programm terminiert nicht, // mit [Control]-C abbrechen !!! // #include int main() { // summiere solange, bis der aktuelle Fehler error // kleiner wird als max_error // oo // -- 1 // Da \ ------------- = 1 , bricht die Schleife // / i * (i + 1) // -- // i = 1 // // nach endlich vielen Iterationen ab. float sum = 0.0f; // Partialsumme float error; // momentaner Fehler const float max_error = 0.0001f; // Fehlerschranke unsigned int i = 1; do { sum += 1.0f / (i * (i + 1.0f)); ++i; error = 1.0f - sum; std::cout << "aktueller Fehler ist " << error << std::endl; } while (error > max_error); // Ausgabe: std::cout << "Summe = " << sum << ".\n" << "Fehler = " << error << std::endl; return 0; }