Advertisement
weldisalves

Lista 03 - exercício 16

Jun 13th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. /* 16. Exiba uma lista de 40 grupos de números sorteados de 0 a 59. Cada grupo possui 3 números que devem ser
  4. exibidos em ordem crescente. */
  5.  
  6. int main()
  7. {
  8.     int sorteado[3],i,j,k,aux;
  9.  
  10.     srand(time(NULL));
  11.  
  12.     for(i=0;i<40;i++)
  13.     {
  14.         printf("\n Grupo %d",i+1);
  15.         for(j=0;j<3;j++)
  16.         {
  17.             sorteado[j]= rand() % 60;
  18.         }
  19.         for(j=0;j<3;j++)
  20.         {
  21.             for(k=0;k<2;k++)
  22.             {
  23.                 if(sorteado[k]>sorteado[k+1])
  24.                 {
  25.                     aux=sorteado[k];
  26.                     sorteado[k]=sorteado[k+1];
  27.                     sorteado[k+1]=aux;
  28.                 }
  29.             }
  30.         }
  31.         for(j=0;j<3;j++)
  32.         {
  33.             printf("\n %d",sorteado[j]);
  34.         }
  35.         printf("\n");
  36.     }
  37.  
  38.     getchar();
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement