fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, s=1;
  6. cin>>n;
  7. deque<int>arr(n, 1);
  8. for (int i=1; i<n; i++){
  9. arr[i] = arr[i-1] + 2;
  10. }
  11. for (int i=1; i<=n; i++){
  12. for (int j=0; j<n; j++){
  13. cout<<arr[j]<<" ";
  14. }
  15. s = arr.front();
  16. arr.pop_front();
  17. arr.push_back(s);
  18. cout<<endl;
  19. }
  20. return 0;
  21. }
Success #stdin #stdout 0s 5320KB
stdin
5
stdout
1 3 5 7 9 
3 5 7 9 1 
5 7 9 1 3 
7 9 1 3 5 
9 1 3 5 7