gpsgiraldi

2024_fun_with_s_&_rand

Jun 3rd, 2024
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main()
  6. {
  7.     int i,j,n,m;
  8.     printf("Escolha o tamanho da matriz quadrada... \n");
  9.     scanf("%d",&n);
  10.    
  11.     int mat[n][n];
  12.     srand(time(NULL));
  13.    
  14.     printf("Escolha um valor limite para gerar valores aleatórios...\n");
  15.     scanf("%d",&m);
  16.    
  17.     for(i=0;i<n;i++){
  18.         for(j=0;j<n;j++){
  19.             mat[i][j]=rand()%m;
  20.         }
  21.     }
  22.     for(i=0;i<n;i++){
  23.         for(j=0;j<n;j++){
  24.             printf("%d ",mat[i][j]);
  25.         }
  26.         printf("\n");
  27.     }
  28.    
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment