2차원 배열 방향 연습

computer_log·2023년 8월 29일
0

#include <iostream>
#include <vector>

using namespace std;

int map[3][3] = {
	{0,2,1},
	{0,1,3},
	{4,5,6}
};
int main() {
	//1. 정방향 읽기

	for (int y = 0; y < 3; y++) {
		for (int x = 0; x < 3; x++) {
			cout << map[y][x] << " ";
		}
		cout << "\n";
	}

	//2. 아래로 읽기
	for (int x = 0; x < 3; x++) {
		for (int y = 0; y < 3; y++) {
			cout << map[y][x] << " ";
		}
		cout << endl;
	}

	for (int x = 0; x < 3; x++) {
		for (int y = 2; y >= 0; y--) {
			cout << map[y][x] << " ";
		}
		cout << endl;
	}
	return 0;
}
profile
computer_log

0개의 댓글