Skip to content

Instantly share code, notes, and snippets.

@peterbrendel
Created April 11, 2017 20:59
Show Gist options
  • Save peterbrendel/6133f672dd4e166bab8a0d42b616c7f9 to your computer and use it in GitHub Desktop.
Save peterbrendel/6133f672dd4e166bab8a0d42b616c7f9 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void preparar(int baralho[][13]);
void distribuir(int baralho[][13], const char *naipes[],
const char *valores[]);
int main(void){
int baralho[4][13] = {0};
const char *naipes[4] = {"ouro", "espada",
"paus", "copas"};
const char *valores[13] = {"As", "Dois", "Tres",
"Quatro", "Cinco","Seis",
"Sete","Oito","Nove","Dez",
"Valete","Dama","Rei"};
srand(time(NULL));
preparar(baralho);
distribuir(baralho, naipes, valores);
return 0;
}
void preparar(int baralho[][13]){
int i, l, c;
for(i=1; i<=52; i++){
do{
l = rand()%4;
c = rand()%13;
}while(baralho[l][c] != 0);
baralho[l][c] = i;
}
}
void distribuir(int baralho[][13],
const char *naipes[],
const char *valores[]){
int i, l, c;
for(i=1; i<=52; i++){
for(l=0; l<4; l++){
for(c=0; c<13; c++){
if(i == baralho[l][c]){
printf("%s\tde\t%s\n", valores[c],
naipes[l]);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment