-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUntitled-1.cpp
More file actions
75 lines (75 loc) · 1.69 KB
/
Untitled-1.cpp
File metadata and controls
75 lines (75 loc) · 1.69 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <time.h>
using namespace std;
void inicializarArreglo(int vec[], int t, int valor)
{
for (int i = 0; i < t; i++)
{
vec[i] = valor;
}
}
void imprimirJuegoPropuesto(int vec[], int tam)
{
cout << "Lo que se encuentra en el arreglo: " << endl;
for (int i = 0; i < tam; i++)
{
cout << " " << vec[i] << " ";
}
}
void proponerJuego(int vec[], int limite, int menor, int mayor) //000000
{
for (int i = 0; i < limite; i++)
{
bool se_repite = true;
int comparacion = 0;
// 1. Obtener el valor aleatorio
while (se_repite) // mientras se repita
{
comparacion = rand() % (mayor - menor + 1) + menor;
// 2. Verificar que no se repitan los valores aleatorios y/o mirar si el valor ya existe en el arreglo
bool existente = false;
for (int a = 0; a < limite; a++)
{
if (comparacion == vec[a]) // 3. Cambiar el numero repetido, unicamente si se repite
{
existente = true;
}
}
se_repite = existente;
}
// 4. Guardar
vec[i] = comparacion;
}
}
void organizar(int vec[], int tam)
{
int aux;
for (int i = 0; i < tam; i++)
{
for (int j = 0; j < tam; j++)
{
if (vec[j] > vec[j + 1])
{
aux= vec[j];
vec[j] = vec[j + 1];
vec[j + 1] = aux;
}
}
}
}
int main()
{
srand(time(NULL));
const int T = 100;
int arreglo[T];
int tam = 6;
inicializarArreglo(arreglo, tam, 0);
imprimirJuegoPropuesto(arreglo, tam);
proponerJuego(arreglo, tam, 1, 43);
organizar(arreglo,tam);
imprimirJuegoPropuesto(arreglo, tam);
proponerJuego(arreglo, tam, 1, 43);
organizar(arreglo,tam);
imprimirJuegoPropuesto(arreglo, tam);
return 0;
}