Advertisement
weldisalves

Lista 05 - exercício 09

Jun 28th, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. /* 9. Preencha uma matriz com números aleatórios (inteiros). Para isto solicite ao usuário quantas
  5. linhas e colunas a matriz possui, e a faixa de números que devem ser sorteados.
  6. Exiba todo o conteúdo da matriz de forma organizada, por exemplo, uma matriz de 3 linhas e 6
  7. colunas com números sorteados entre 1000 e 3000, seria exibida desta forma:
  8. 1003 1569 1789 1110 2000 1212
  9. 1103 1662 1989 1200 2406 1819
  10. 1045 1749 1980 1310 2507 1815 */
  11.  
  12. int main()
  13. {
  14.     int quantLinhas,quantColunas,i,j,limiteInferior,LimiteSuperior;
  15.  
  16.     printf("\n Digite a quantidade de Linhas e coluna da matriz: ");
  17.     scanf("%d %d",&quantLinhas,&quantColunas);
  18.  
  19.     printf("\n Digite o limite inferior e superior do sorteio: ");
  20.     scanf("%d %d",&limiteInferior,&LimiteSuperior);
  21.  
  22.     int matriz[quantLinhas][quantColunas];
  23.  
  24.     for(i=0;i<quantLinhas;i++)
  25.     {
  26.         for(j=0;j<quantColunas;j++)
  27.         {
  28.             matriz[i][j]=(rand()%(LimiteSuperior-limiteInferior+1))+limiteInferior;
  29.             printf("%d ",matriz[i][j]);
  30.         }
  31.         printf("\n");
  32.     }
  33.  
  34.     getchar();
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement