Phoenix_x

Untitled

Feb 4th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. void left();
  7. void bottom();
  8. void right();
  9. void top();
  10. void read();
  11. void printMatrix();
  12.  
  13. const int x = 4;
  14. const int y = 4;
  15.  
  16. int fillNumber = 0;
  17. int goInside = 0;
  18. int matrix[y][x];
  19.  
  20. void main()
  21. {
  22.     cout << "Input: " << endl;
  23.     while (fillNumber < x * y) { // 5 x 5 = 25
  24.         read();
  25.         goInside++;
  26.     }
  27.  
  28.     cout << "Output:" << endl;
  29.     printMatrix();
  30. }
  31.  
  32. void left()
  33. {
  34.     for (int i = y - 2 -goInside; i >= 1 + goInside; i--)
  35.     {
  36.         cin >> matrix[i][0 + goInside];
  37.         fillNumber++;
  38.     }
  39. }
  40.  
  41. void right() {
  42.     for (int i = 1 + goInside; i < y - goInside; i++) {
  43.         cin >> matrix[i][x - 1 - goInside];
  44.         fillNumber++;
  45.     }
  46. }
  47.  
  48. void  top() {
  49.     for (int i = 0 + goInside; i < x - goInside; i++) {
  50.         cin >> matrix[0 + goInside][i];
  51.         fillNumber++;
  52.     }
  53. }
  54.  
  55. void bottom() {
  56.     for (int i = x - goInside - 2; i >= 0 + goInside; i--) {
  57.         cin >> matrix[y - 1 - goInside][i];
  58.         fillNumber++;
  59.     }
  60. }
  61.  
  62. void read()
  63. {
  64.     top();
  65.     right();
  66.     bottom();
  67.     left();
  68. }
  69.  
  70. void printMatrix()
  71. {
  72.     for (int i = 0; i < y; i++)
  73.     {
  74.         for (int j = 0; j < x; j++)
  75.         {
  76.             cout << matrix[i][j] << "\t";
  77.         }
  78.  
  79.         cout << endl;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment