Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solución reto 3 en C++ #1297

Open
yasperht opened this issue Feb 13, 2024 · 0 comments
Open

Solución reto 3 en C++ #1297

yasperht opened this issue Feb 13, 2024 · 0 comments

Comments

@yasperht
Copy link

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

void fibonacciLineal (int n){
    long long a, b, aux;

    for (int i{}; i <= n; i++) { 
        if (i == 0) {cout << i << " "; a = i; continue;}
        if (i == 1) {cout << i << " "; b = i; continue;}

        cout << a + b << " ";
        aux = a;
        a = b;
        b += aux;
    }
}

long long fibonacciRecursivo (int n){
    
    if (n == 0) {return 0;}
    if (n == 1) {return 1;}

    return fibonacciRecursivo(n - 1) + fibonacciRecursivo(n - 2);
}

int main (){
    system("cls");
    int n = 0;

    cout << "Enter the value of n for the Fibonacci Sequence: ";
    cin >> n;
    
    fibonacciLineal(n);
    //cout << fibonacciRecursivo(n) << endl;

    cout << endl << endl;
    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant