Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- void left();
- void bottom();
- void right();
- void top();
- void printFrame();
- const int x = 5;
- const int y = 5;
- int fillNumber = 0;
- int goInside = 0;
- int matrix[y][x] =
- {
- { 1, 2, 3, 4, 5 },
- { 16, 17, 18, 19, 6 },
- { 15, 24, 25, 20, 7 },
- { 14, 23, 22, 21, 8 },
- { 13, 12, 11, 10, 9 }
- };
- void main()
- {
- while (fillNumber <= x * y) { // 5 x 5 = 25
- printFrame();
- goInside++;
- }
- }
- void left()
- {
- for (int i = y - 2 -goInside; i >= 1 + goInside; i--)
- {
- cout << matrix[i][0 + goInside] << " ";
- fillNumber++;
- }
- }
- void right() {
- for (int i = 1 + goInside; i < y - goInside; i++) {
- cout << matrix[i][x - 1 - goInside] << " ";
- fillNumber++;
- }
- }
- void top() {
- for (int i = 0 + goInside; i < x - goInside; i++) {
- cout << matrix[0 + goInside][i] << " ";
- fillNumber++;
- }
- }
- void bottom() {
- for (int i = x - goInside - 2; i >= 0 + goInside; i--) {
- cout << matrix[y - 1 - goInside][i] << " ";
- fillNumber++;
- }
- }
- void printFrame()
- {
- top();
- right();
- bottom();
- left();
- }
Add Comment
Please, Sign In to add comment