Coding Problem: Complete the following program so that the output of the program
ID: 3760365 • Letter: C
Question
Coding Problem:
Complete the following program so that the output of the program becomes:
A =
1 2 3 4 5 6
7 8 9 10 11 12
1 2 3 4 5 6
--------------------------
Program:
#include
#define M 3
#define N 6
void fun(int **A, int m, int n);
int main() {
int a[M][N] = { 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12,
1, 2, 3, 4, 5, 6};
int **A;
/* add code for passing a through A to fun() here */
fun(A, M, N);
/* add any code necessary here */
}
void fun(int **A, int m, int n) {;
/* add code for print out, using A[0][0], ..., A[m=1][n-1] */
return 0;
}
Explanation / Answer
#include
#define M 3
#define N 6
void fun(int **A, int m, int n);
int main() {
int a[M][N] = { 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12,
1, 2, 3, 4, 5, 6};
int **A;
/* add code for passing a through A to fun() here */
fun(A, M, N);
/* add any code necessary here */
}
void fun(int **A, int m, int n) {;
for (int i=0;i<m; i++)
{ for ( int j=0;j < n; j++)
{ System.out.println(A[i] [j] +" " );
}
}
return 0;
}