I'm trying to figure out the value of A, B and C at the end of the program. When I try to cout using for loop, I get a whole list of values. I need a matrix format only.
#include <iostream>
using namespace std;
int main()
{
int m = 3;
int A[m] [m] = {};
int B[m] [m + 1] = {};
int C[m + 1] [m] = {};
int counter = 0, k = 2;
for (int i=1; i<=m; i++)
{
for (int j=1; j<=m; j++)
{
A[i-1][i-1] = counter;
B[i][j] = counter;
C[j-1][j-1] = k;
}
counter++;
k += 3;
}
//Printing C
//get array columns and rows
int rows = sizeof C/ sizeof A[0];
int cols = sizeof C[0] / sizeof(int);
// Print 2d Array
cout << "your_array data "<<endl<<endl;
for (int i = 0; i < rows; ++i)
{
for (int j = 0; j < cols; ++j)
{
std::cout << C[i][j] << std::endl;
}
}
return 0;
}