1 Attachment(s)

Why aren't '1' of "col 1" and "1" aligned?

Hi

I attached a screenshot from the output of the following code. Why aren't '1' of "col 1" and "1" (matrix entry) aligned? Could you please tell me the reason for this?

Code:

`// read 3x4 matrix. print it, find the largest value,`

// count number of zeroes;

#include <iostream>

#include <cstdlib>

#include <iomanip>

using namespace std;

int main()

{

const int R = 3;

const int C = 4;

float m[R][C];

float largest = 0;

float smallest = 10000;

int num_zeros = 0;

int r, c;

int entered_largest_r = 0, entered_largest_c = 0;

int entered_smallest_r = 0, entered_smallest_c = 0;

cout << "enter the matrix below\n\n";

for ( r=0; r<R; r++ )

{

for ( c=0; c<C; c++ )

{

cout << "enter entry for row #" << (r+1)

<< " and column #" << (c+1) << ": ";

cin >> m[r][c];

if ( m[r][c] > largest)

{

largest = m[r][c];

entered_largest_r = r+1;

entered_largest_c = c+1;

}

if ( m[r][c] < smallest )

{

smallest = m[r][c];

entered_smallest_r = r+1;

entered_smallest_c = c+1;

}

if ( m[r][c] == 0)

{

num_zeros = num_zeros++;

}

}

}

cout << "\n\n";

cout << "entered matrix is given below\n\n";

cout << setw(10) << "" << setw(10) << "col 1" << setw(10) << "col 2"

<< setw(10) << "col 3" << setw(10) << "col 4\n\n";

for( r=0; r<R; r++ )

{

cout << "\n" << setw(10) << "row " << (r+1);

for( c=0; c<C; c++)

{

cout << setw(10) << m[r][c];

}

}

cout << "\n\n\n";

cout << "largest matric element is: " << largest << ", entered at row #" << entered_largest_r

<< " and column #" << entered_largest_c << "\n\n";

cout << "smallest matrix element is: " << smallest << ", entered at row #" << entered_smallest_r

<< " and column #" << entered_smallest_c << "\n\n";

cout << "number of '0' matrix element(s): " << num_zeros << endl << endl;

system("pause");

return 0;

}