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 read();
- void printMatrix();
- const int x = 4;
- const int y = 4;
- int fillNumber = 0;
- int goInside = 0;
- int matrix[y][x];
- void main()
- {
- cout << "Input: " << endl;
- while (fillNumber < x * y) { // 5 x 5 = 25
- read();
- goInside++;
- }
- cout << "Output:" << endl;
- printMatrix();
- }
- void left()
- {
- for (int i = y - 2 -goInside; i >= 1 + goInside; i--)
- {
- cin >> matrix[i][0 + goInside];
- fillNumber++;
- }
- }
- void right() {
- for (int i = 1 + goInside; i < y - goInside; i++) {
- cin >> matrix[i][x - 1 - goInside];
- fillNumber++;
- }
- }
- void top() {
- for (int i = 0 + goInside; i < x - goInside; i++) {
- cin >> matrix[0 + goInside][i];
- fillNumber++;
- }
- }
- void bottom() {
- for (int i = x - goInside - 2; i >= 0 + goInside; i--) {
- cin >> matrix[y - 1 - goInside][i];
- fillNumber++;
- }
- }
- void read()
- {
- top();
- right();
- bottom();
- left();
- }
- void printMatrix()
- {
- for (int i = 0; i < y; i++)
- {
- for (int j = 0; j < x; j++)
- {
- cout << matrix[i][j] << "\t";
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment