fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4.  
  5. int main()
  6. {
  7. std::string arr[]={"2","1","3","16","8","3","4","1","2"};
  8. const int arrlength = sizeof(arr)/sizeof(*arr);
  9. const int matrixSize = 3;
  10.  
  11. for(int row = 0; row < matrixSize; ++row)
  12. {
  13. for (int index = row; index < arrlength ; index += matrixSize)
  14. std::cout << arr[index] << std::setw(5);
  15. std::cout << "\n";
  16. }
  17.  
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0s 4260KB
stdin
Standard input is empty
stdout
2   16    4    
1    8    1    
3    3    2