-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTribonacci.cpp
More file actions
34 lines (25 loc) · 850 Bytes
/
Tribonacci.cpp
File metadata and controls
34 lines (25 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;
void crearSecuenciaTribonacci(int totalElementos) {
int valor1 = 0, valor2 = 1, valor3 = 1, proximoValor;
cout << valor1 << " " << valor2 << " " << valor3 << " ";
for (int indice = 3; indice < totalElementos; indice++) {
proximoValor = valor1 + valor2 + valor3;
cout << proximoValor << " ";
valor1 = valor2;
valor2 = valor3;
valor3 = proximoValor;
} //geofrey ando probando
cout << endl;
}
int main() {
int cantidadElementos;
cout << "Ingrese el número total de elementos para la secuencia Tribonacci: ";
cin >> cantidadElementos;
if (cantidadElementos < 3) {
cout << "Por favor, ingrese un valor mayor o igual a 3." << endl;
return 1;
}
crearSecuenciaTribonacci(cantidadElementos);
return 0;
}