Guest User

Untitled

a guest
Aug 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define NUM 6
  5.  
  6. int main(){
  7.    
  8.     int i,j,k,r,used;
  9.     int v[NUM];
  10.     char people[][200]={"Fulando","Beltrano","Ciclano","Xuxa","Sacha","Papa"};
  11.    
  12.     /*Repete a bagaça toda*/
  13.     for(k=0;k<3;k++){
  14.        
  15.         /* Gera a permutacao aleatoria: */
  16.         srand(time(NULL));
  17.         for(i=0;i<NUM;i++){
  18.             do{
  19.                 r=rand()%NUM;
  20.                
  21.                 used = 0;
  22.                 for(j=0;j<i;j++)
  23.                     if (r==v[j])
  24.                         used=1;            
  25.             }while(used);
  26.             v[i]=r;
  27.         }
  28.        
  29.         /*Quem pergunta pra quem :*/
  30.         printf("Sorteio %d:\n",k);
  31.         for (i=0;i<NUM;i++)
  32.             printf("%20s pergunta pra %-20s\n",people[v[i]],people[v[(i+1)%NUM]]);
  33.         printf("\n\n");
  34.     }
  35.    
  36.     return 0;
  37. }
Add Comment
Please, Sign In to add comment