Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main ()
  4. {
  5. int n, mt[100][100];
  6. cin >> n;
  7. for (int i = 1; i <= n; i++)
  8. for (int j = 1; j <= n; j++)
  9. cin >> mt[i][j]; // citim matricea
  10. int x = 1, l = n; // initializam x, y captul spiralei si lunngimea
  11. for (int i = 1; i < n; i++)
  12. {
  13. cout << mt[x][x] << " ";
  14. for (int j = x + 1; j <= l; j++)
  15. cout << mt[x][j] << " "; // orizontala sus
  16. for (int j = x + 1; j <= l; j++)
  17. cout << mt[j][l] << " "; // verticala dreapta
  18. for (int j = l - 1; j >= x; j--)
  19. cout << mt[l][j] << " "; // orizontala jos
  20. for (int j = l - 1; j > x; j--)
  21. cout << mt[j][x] << " "; // verticala stanga
  22. l--;
  23. x++;
  24. }
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement