배열은 인수로 함수에 전달할 수 있습니다. 이 프로그램에서는 2차원 배열의 요소를 함수에 전달하여 표시하는 작업을 수행합니다.
알고리즘
Begin The 2D array n[][] passed to the function show(). Call function show() function, the array n (n) is traversed using a nested for loop. End
예시 코드
#include <iostream>
using namespace std;
void show(int n[4][3]);
int main() {
int n[4][3] = {
{3, 4 ,2},
{9, 5 ,1},
{7, 6, 2},
{4, 8, 1}};
show(n);
return 0;
}
void show(int n[][3]) {
cout << "Printing Values: " << endl;
for(int i = 0; i < 4; ++i) {
for(int j = 0; j < 3; ++j) {
cout << n[i][j] << " ";
}
}
} 출력
Printing Values: 3 4 2 9 5 1 7 6 2 4 8 1