Modernes C++ programmieren

Okt 23, 2024

lst-0002-book.cpp

// https://godbolt.org/z/aEvcPWzn5 
// modern101.cpp : Fibonacci-Konsole
#include <iostream>
int fib(int n) {
    return n<=1 ? n : fib(n-2) + fib(n-1);
}
int main() {
    std::cout << "Die wievielte Fibonacci-Zahl? ";
    int n = 0;
    std::cin >> n;
    std::cout << "fib(" << n << ")=" << fib(n) << "\n";
}