Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

//========================================================//

// Programa: PGM001.cpp Genera los valores de un BINGO //


// Autor: Roberto Tello Yuen Fecha: 05/05/2023 //
//========================================================//
#include <iostream>
#include <ctime>
using namespace std;

bool f_existe(int bolo, int Bingo[50][50], int cant_filas, int j) {


bool exito = false;
for (int i = 0; i < cant_filas; i++) {
if (Bingo[i][j] == bolo){
exito = true;
break;
}
}
return exito;
}

int main() {
// Declaración de variables y constantes
int Bingo[50][50];
int repetidos[2500];
int i, cant_filas = 9;
int j, cant_colum = 5;
int bolo;
int k, total_iteraciones;
srand(time(NULL));
total_iteraciones = 0;
//Generación de valores aleatorios (columna x columna)
j = 0; k = 0;
while (j < cant_colum) {
i = 0;
while (i < cant_filas) {
bolo = (rand() % 15 + 1) + (15 * j);
total_iteraciones += 1;
if (!f_existe(bolo, Bingo, cant_filas, j)) {
Bingo[i][j] = bolo;
i++;
}
else {
repetidos[k] = bolo;
k += 1;
}
}
j++;
}

// Impresión de resultados (fila por fila)


i = 0;
while (i < cant_filas) {
j = 0;
while (j < cant_colum) {
cout << " " << Bingo[i][j];
j++;
}
cout << endl;
i++;
}
cout << "Se generaron " << total_iteraciones << " iteraciones..." << endl;
cout << "Los elementos repetidos son:\n";
for (int i = 0; i < k; i++) {
cout << repetidos[i] << " ";
}
cout << "\nFin del Programa\n";

system("Pause");
return 0;
}

You might also like