c program of printing 3×3 matrix Using 2d array

c program of printing 3×3 matrix Using 2d array

  1. #include<stdio.h>
  2. int main()
  3. {
  4.   int row,col, arr[3][3];
  5.     //Logic to read matrix 
  6.       for(row=0; row<3; row++) // rows
  7.         {
  8.             for(col=0; col<3; col++) //columns
  9.                 {
  10. printf("Enter matrix number[%d][%d]:", row, col);
  11. scanf("%d", &arr[row][col]);
  12.               }
  13.      }
  14. //Logic to print matrix
  15. printf("The 3 X 3 matrix:\n");
  16. for(row=0; row<3; row++) // rows
  17.                                             {
  18. for(col=0; col<3; col++) //columns
  19.   {
  20. printf("%d ", arr[row][col])

  21. }
  22. printf("\n");
  23.     }
  24. return 0; 
  25. }

Output


Enter matrix number[0][0]:1
Enter matrix number[0][1]:2
Enter matrix number[0][2]:3
Enter matrix number[1][0]:4
Enter matrix number[1][1]:5
Enter matrix number[1][2]:6
Enter matrix number[2][0]:7
Enter matrix number[2][1]:8
Enter matrix number[2][2]:9
The 3 X 3 matrix:
1 2 3
4 5 6
7 8 9

choose next program from this list

Comments