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

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

// Programm: harakiri.C // Berechnung der N-ten harmonischen Zahl. #include int main() { // Eingabe std::cout << "Welche harmonische Zahl H_N (1 <= N <= " << std::numeric_limits::max() << ") ? "; unsigned int N; std::cin >> N; // Berechnung der harmonischen Zahl float sum = 0.0f; unsigned int i = 1; while (i <= N) { sum = sum + 1 / i; i = i + 1; } // Ausgabe std::cout << "H_" << N << " = " << sum << std::endl; return 0; }