Advertisement
Niloy007

2D Array

Nov 4th, 2020
1,897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     int m, n;
  5.     scanf("%d %d", &m, &n);
  6.  
  7.     int arr[m][n];
  8.  
  9.     // input
  10.     for (int row = 0; row < m; row++) {
  11.         for (int col = 0; col < n; col++) {
  12.             scanf("%d", &arr[row][col]);
  13.         }
  14.     }
  15.     printf("\n");
  16.  
  17.     // Row-wise
  18.     printf("Row-wise: ");
  19.     for (int row = 0; row < m; row++) {
  20.         for (int col = 0; col < n; col++) {
  21.             printf("%d ", arr[row][col]);
  22.         }
  23.     }
  24.  
  25.     printf("\n");
  26.     // Column-wise
  27.     printf("Column-wise: ");
  28.     for (int row = 0; row < n; row++) {
  29.         for (int col = 0; col < m; col++) {
  30.             printf("%d ", arr[col][row]);
  31.         }
  32.     }
  33.  
  34.  
  35.     printf("\n");
  36. }
  37.  
  38. // int main() {
  39. //  int n, m;
  40. //  printf("Enter row and column:\n");
  41. //  scanf("%d %d", &n, &m);
  42.  
  43. //  int arr[n][m];
  44. //  // Print
  45. //  // printf("%d %d %d\n", arr[0][0], arr[0][1], arr[0][2]);
  46.  
  47.  
  48. //  // input
  49. //  for (int row = 0; row < n; row++) {
  50. //      for (int col = 0; col < m; col++) {
  51. //          scanf("%d", &arr[row][col]);
  52. //      }
  53. //  }
  54. //  printf("\n");
  55.  
  56. //  // Output
  57. //  for (int row = 0; row < n; row++) {       // -> outer loop
  58. //      for (int col = 0; col < m; col++) {   // -> inner loop
  59. //          printf("%d ", arr[row][col]);
  60. //      }
  61. //      printf("\n");
  62. //  }
  63.  
  64. //  printf("\n");
  65. // }
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement