menu

Sabtu, 09 April 2016

Algoritma dan program no 2 hal 120

#include <iostream>
using namespace std;
int nextTerm(int n){
    int firstTerm = 0, secondTerm = 1;
    int nextTerm;
    cout << "Fibonacci Series: " << firstTerm << " " << secondTerm << " ";
    for (int i = 1; i <= n-2; ++i) {
        nextTerm = firstTerm + secondTerm;
        cout<<nextTerm << " ";
        firstTerm = secondTerm;
        secondTerm = nextTerm;
    }
}
int main() {
    int n;
    cout << "Enter number of terms: ";
    cin >> n;
    nextTerm(n);
    return 0;
}

Tidak ada komentar:

Posting Komentar