// Pantea Aria // static 2D arrays recap // You are given two 2D arrays of integers (table1 and table2) // with the same number of rows and columns. // Write a function called add_tables that: // Takes table1, table2, and sum as parameters // Adds the corresponding elements of table1 and table2 // Stores the sum in result // Write a function called print_table that prints a 2D array in grid form. #include #define ROWS 2 #define COLS 3 void print_array(int array[ROWS][COLS]); void add_tables(int table1[ROWS][COLS], int table2[ROWS][COLS], int sum[ROWS][COLS]); int main(void) { int table1[ROWS][COLS] = { {1, 2, 3}, {4, 5, 6} }; int table2[ROWS][COLS] = { {7, 8, 9}, {1, 2, 3} }; int sum[ROWS][COLS]; // call function add_tables add_tables(table1, table2, sum); printf("Table 1\n"); // call function print_table print_array(table1); printf("\nTable 2\n"); // call function print_table print_array(table2); printf("\nSum Table\n"); // call function print_table print_array(sum); } void add_tables(int table1[ROWS][COLS], int table2[ROWS][COLS], int sum[ROWS][COLS]) { int i = 0; while(i < ROWS) { int j = 0; while(j < COLS) { sum[i][j] = table1[i][j] + table2[i][j]; j++; } i++; } return; } void print_array(int array[ROWS][COLS]) { int i = 0; while(i < ROWS) { int j = 0; while(j < COLS) { printf("%3d", array[i][j]); j++; } printf("\n"); i++; } }