fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4.  
  5. void shuffle(int *array, int size) {
  6. for (int i = size - 1; i > 0; i--) {
  7. int j = rand() % (i + 1);
  8. int tmp = array[j];
  9. array[j] = array[i];
  10. array[i] = tmp;
  11. }
  12. }
  13.  
  14. int main() {
  15. srand(time(NULL));
  16. int p1 = 0;
  17. int p2 = 0;
  18. int c1[4][4], c2[4][4];
  19. int numbers[50];
  20. for (int i = 0; i < 50; i++) numbers[i] = i + 1;
  21. shuffle(numbers, 50);
  22. for (int i = 0; i < 4; i++) {
  23. for (int j = 0; j < 4; j++) {
  24. c1[i][j] = numbers[i * 4 + j];
  25. printf("%i\t", c1[i][j]);
  26. }
  27. printf("\n");
  28. }
  29. printf("\n");
  30. shuffle(numbers, 50);
  31. for (int i = 0; i < 4; i++) {
  32. for (int j = 0; j < 4; j++) {
  33. c2[i][j] = numbers[i * 4 + j];
  34. printf("%i\t", c2[i][j]);
  35. }
  36. printf("\n");
  37. }
  38. printf("\n");
  39. shuffle(numbers, 50);
  40. for (int k = 0; k < 50 && (p1 <= 16 || p2 <= 16); k++) {
  41. int sorteio = numbers[k];
  42. printf ("%i ", sorteio);
  43. for (int i = 0; i < 4; i++) {
  44. for (int j = 0; j < 4; j++) {
  45. if (c1[i][j] == sorteio) p1++;
  46. if (c2[i][j] == sorteio) p2++;
  47. }
  48. }
  49. }
  50. if (p1 == 16) printf("\nBingo! Jogador 1 ganhou\n");
  51. else if (p2 == 16) printf("\nBingo! Jogador 2 ganhou\n");
  52. else printf("\nempate");
  53. }
  54.  
  55. //https://pt.stackoverflow.com/q/390787/101
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
2	44	46	19	
5	3	21	11	
27	32	1	26	
7	23	43	30	

20	42	41	10	
28	40	23	22	
21	32	50	9	
43	14	48	19	

17 2 1 3 8 30 5 19 50 13 35 34 41 9 33 28 42 40 12 4 18 32 6 49 31 29 36 45 23 26 11 10 39 7 44 43 37 47 20 16 22 24 14 46 48 27 21 15 38 25 
Bingo! Jogador 1 ganhou