maikonsx

numerosaleatórios.c

Nov 27th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. void main(){
  6.  
  7. int l, c, i, j, matriz[6][6];
  8. srand(time(NULL));
  9.  
  10. int comparador = 0;
  11.  
  12. //preenche a matriz com 0.
  13. for(l=0; l<6; l++){
  14.     for(c=0; c<6; c++){
  15.         matriz[l][c] = 0;
  16.     }
  17. }
  18.  
  19.  
  20. for(l=0; l<6; l++){
  21.     for(c=0; c<6; c++){
  22.         if(comparador == 0){
  23.  
  24.             matriz[l][c] = rand() % 18;
  25.             comparador = 1;
  26.  
  27.             for(i=0; i<l; i++){
  28.                 for(j=0; j<c; j++){
  29.                     if(matriz[l][c] = matriz[i][j]){
  30.                         comparador = 0;
  31.                         }
  32.                     }
  33.                 }
  34.             }
  35.             printf(" %i ", matriz[l][c]);
  36.         }
  37.         puts("");
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment