fork download
  1. #include <stdio.h>
  2.  
  3. #define ROWS 3
  4. #define COLS 3
  5.  
  6. void readArray(int arr[ROWS][COLS]) {
  7. printf("Enter elements of the 2D array (%d x %d):\n", ROWS, COLS);
  8. for (int i = 0; i < ROWS; i++) {
  9. for (int j = 0; j < COLS; j++) {
  10. printf("Enter element at position [%d][%d]: ", i, j);
  11. scanf("%d", &arr[i][j]);
  12. }
  13. }
  14. }
  15.  
  16. void printArray(int arr[ROWS][COLS]) {
  17. printf("The 2D array is:\n");
  18. for (int i = 0; i < ROWS; i++) {
  19. for (int j = 0; j < COLS; j++) {
  20. printf("%d ", arr[i][j]);
  21. }
  22. printf("\n");
  23. }
  24. }
  25.  
  26. int main() {
  27. int array[ROWS][COLS];
  28.  
  29. readArray(array);
  30. printf("\n");
  31.  
  32. printArray(array);
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Enter elements of the 2D array (3 x 3):
Enter element at position [0][0]: Enter element at position [0][1]: Enter element at position [0][2]: Enter element at position [1][0]: Enter element at position [1][1]: Enter element at position [1][2]: Enter element at position [2][0]: Enter element at position [2][1]: Enter element at position [2][2]: 
The 2D array is:
58030880 5248 0 
0 25916096 22007 
25915600 22007 -94029232