Advertisement
Guest User

Matrice diagonale (Planète Casio)

a guest
Aug 18th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. /*** CODE POUR UN TABLEAU 2D ***/
  2.  
  3. void remplir_matrice(int *matrice, int dim_x, int dim_y)
  4. {
  5.     int x, y;
  6.    
  7.     for(y = 0; y < dim_y; y++)
  8.     {
  9.         for(x = 0; x < dim_x; x++)
  10.         {
  11.             if(x == y)
  12.                 matrice[ y * dim_x + x ] = 1;
  13.             else
  14.                 matrice[ y * dim_x + x ] = 0;
  15.         }
  16.     }
  17. }
  18.  
  19. int main()
  20. {
  21.     int ma_matrice[5][5];
  22.    
  23.     remplir_matrice(ma_matrice, 5, 5);
  24. }
  25.  
  26.  
  27. /*** CODE EXEMPLE POUR UN TABLEAU 5D ***/
  28.  
  29. int lire_case_tableau(int *matrice, int dim_1, int dim_2, int dim_3, int dim_4, int dim_5)
  30. {
  31.     int c_1, c_2, c_3, c_4, c_5; // coordonnées de la case à lire, je ne les initialise pas volontairement, c'est à vous de le faire.
  32.    
  33.     return matrice[ c_5 * dim_4 + c_4 * dim_3 + c_3 * dim_2 + c_2 * dim_1 + c_1 ];
  34. }
  35.  
  36. int main()
  37. {
  38.     int nombre;
  39.     int ma_matrice[2][3][4][5][6];
  40.    
  41.     nombre = lire_case_tableau(ma_matrice, 2, 3, 4, 5, 6);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement