Skip to content

Commit a3404d2

Browse files
authored
Merge pull request mouredev#3136 from Vid92/main
#6 - C++
2 parents 95de7c6 + 3bce71b commit a3404d2

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int n = 0;
5+
int a = 0;
6+
int b = 1;
7+
8+
int imprimeNumeros(int inicio){
9+
if(inicio==0){
10+
cout<<inicio<<endl;
11+
return 0;
12+
}
13+
else
14+
cout<<inicio<<", ";
15+
return imprimeNumeros(inicio-1);
16+
}
17+
18+
19+
int factorial(int numero){
20+
if(numero<0){
21+
cout<<endl<<"Factorial - Numero negativo, no valido!"<<endl;
22+
return 0;
23+
}
24+
if(numero==0)
25+
return 1;
26+
else
27+
return numero * factorial(numero-1);
28+
}
29+
30+
int fibonacci(int pos){
31+
if(pos<0){
32+
cout<<"Fibonacci, Posicion no valida!"<<endl;
33+
return 0;
34+
}
35+
if(pos==1)
36+
return n;
37+
38+
n = a + b;
39+
b = a;
40+
a = n;
41+
return fibonacci(pos-1);
42+
}
43+
44+
int main()
45+
{
46+
//Ejercicio
47+
imprimeNumeros(100);
48+
49+
//Extra
50+
int fact = 8;
51+
int resultado = factorial(fact);
52+
if(fact>=0)
53+
cout<<endl<<"El Factorial de "<<fact<<" es: "<<resultado<<endl;
54+
55+
int fibo = 11;
56+
int fib = fibonacci(fibo);
57+
if (fibo >0)
58+
cout<<"El valor fibonacci de "<<fibo<<" es: "<<fib<<endl;
59+
return 0;
60+
}

0 commit comments

Comments
 (0)