Answers for "printing in column c++"

C++
0

printing in column c++

#include <iostream>
#include <iomanip>
#include <string>

int main()
{
   std::string arr[]={"2","1","3","16","8","3","4","1","2"};
   const int arrlength = sizeof(arr)/sizeof(*arr);
   const int matrixSize = 3;

   for(int row = 0; row < matrixSize; ++row)
   {
      for (int index = row; index < arrlength ; index += matrixSize)
         std::cout << arr[index] << std::setw(5);
      std::cout << "\n";
   }

  return 0;
}
Posted by: Guest on March-31-2021

Browse Popular Code Answers by Language