Skip to content

Commit

Permalink
Merge pull request ossamamehmood#1056 from IryaDev/main
Browse files Browse the repository at this point in the history
"Fibonacci sucession"
  • Loading branch information
ossamamehmood committed Oct 4, 2022
2 parents e0edc71 + 0719244 commit 1820e20
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Add Code Here/C++/fibonacci.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
using namespace std;
const string INFO = "Este programa imprime la sucesion de fibonacci desde \
1 hasta N, \nsiendo este ultimo un numero ingresado por el usuario\n";
int main() {
unsigned long long aux = 1, fib = 0, lim, init;
cout << INFO << endl;
cout << "Ingrese un numero para la sucesion de fibonacci: ";
cin >> lim;
if(lim > 0) {
for(init = 1; init <= lim; init++) {
cout << "[" << fib << "] ";
aux += fib; /* lo mismo que aux = aux + fib; */
fib = aux - fib;
}
} else {
cout << "El numero debe ser mayor a cero!!" << endl;
}
cout << "\n";
return 0;
}

0 comments on commit 1820e20

Please sign in to comment.