loteria en c
Publicado por jose fernandez (4 intervenciones) el 07/05/2020 23:22:21
hola buenas tardes me podrían colaborar con el siguiente ejercicio modifique el código realizado teniendo en cuenta lo siguiente, inicialmente se debe pedir el número total de participantes y el programa aleatoria mente colocará los números para participar.
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
int main() {
srand(time(NULL));
int participantes[] = {78, 25, 63, 28, 12, 2, 30, 46};
int i,j;
int num_participantes = sizeof(participantes) / sizeof(int);
int max = participantes[0];
for (i = 0; i < num_participantes; i++) {
if (participantes[i] > max) {
max = participantes[i];
}
}
max = max + 1;
int na;
bool seleccionP[] = {false, false, false, false, false, false, false, false};
//while (seleccionP[0] == false || seleccionP[1] == false || seleccionP[2] == false || seleccionP[3] == false || seleccionP[4] == false || seleccionP[5] == false || seleccionP[6] == false || seleccionP[7] == false) {
for(j = 0; j < sizeof(seleccionP); j++){
na = rand() % max;
printf("resultado de la loteria: %d\n", na);
for (i = 0; i < num_participantes; i++) {
if (participantes[i] == na) {
seleccionP[j] = true;
printf("persona %d fue seleccionada: %d\n", i, na);
}
}
}
printf("todas las personas fueron seleccionadas\n");
return 0;
}
Valora esta pregunta


0