Aliendreamer

matrix in c

Apr 12th, 2022
914
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int rows=5;
  5. int cols=6;
  6. int i, j;
  7.  
  8. int mat[rows][cols]={
  9.     {57,67,77,87,97,107 },
  10.     {117, 127, 137, 147,157,167},
  11.     {177, 187, 197, 207,217,227},
  12.     {237, 247, 257, 267,277,287},
  13.     {297, 307, 317, 327,337,347}
  14. };
  15. printf("Matrix values are:\n");
  16.    for(i=0; i<rows; i++) {
  17.       for(j=0;j<cols;j++) {
  18.         printf("%d ", mat[i][j]);
  19.             printf("\n");
  20.       }
  21.    }
  22.  
  23. printf("Two Dimensional array elements on even coordinate:\n");
  24.    for(i=0; i<rows; i++) {
  25.       for(j=0;j<cols;j++) {
  26.          if( i%2 ==0 && j%2==0){
  27.             printf("%d ", mat[i][j]);
  28.             printf("\n");
  29.          }
  30.       }
  31.    }
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment