Advertisement
DavidsonDFGL

Matrix in C

Nov 15th, 2015
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.32 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void f(int w, int h, void *m)
  4. {
  5.     int (*v)[h] = (int (*)[h]) m;
  6.  
  7.     int i;
  8.     for(i=0; i<w; i++)
  9.     {
  10.         for(int j=0; j<h; j++)
  11.         {
  12.             printf("m[%d][%d] = %d\n",i,j,v[i][j]);
  13.         }
  14.     }
  15. }
  16.  
  17. int main()
  18. {
  19.     int m[2][2];
  20.  
  21.     m[0][0] = 5;
  22.     m[0][1] = 7;
  23.     m[1][0] = 34;
  24.     m[1][1] = 12;
  25.  
  26.     f(2, 2, m);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement