array for a matrix

Hello all again I am doing my best to finish a lab I have and would be glad to be pointed in The right direction. My prof wants me to do a program to calculate a matrix using a array and then invert it. I am catching up on my matrices so it can be a little easyer :P

The programs output is the following:

This program calculates a matrix and inverts it

Original matrix
Enter the first number of column 1: 1
Enter the second number of column 1: 2
Enter the third number of column 1: 3

Enter the first number of column 2: 4
Enter the second number of column 2: 5
Enter the third number of column 2: 6

Enter the first number of column 3: 7
Enter the second number of column 3: 8
Enter the third number of column 3: 9

Original Matrix:
1 2 3
4 5 6
7 8 9

Inverted Matrix:
1 4 7
2 5 8
3 6 9

I do not pretend for anybody to do my homework just a little help and when I can I will post my code to see if I am on track.

I am guessing i should use a
Array [2][2]
A do loop with two nesteed for loops for input storing the values in two variables rows and column array [rows][column] or wait maybe that wont work meewh jajajajaj


Thx for help
~VOYD
Last edited on
closed account (D80DSL3A)
You will need a 3x3 array for the given case, so use A[3][3]. The indexes to use are 0,1,2.
The example you gave has the rows and columns exchanged. This is the transpose of a matrix, not the inverse. Hopefully you have the task correct.

Note that for the 3x3 case you have, the transpose can be found by swapping just 3 pairs of elements (identify them by inspection).
If A is a MxN matrix then AT is a NxM matrix such that ATji = Aij for all 0 <= i < M and 0 <= j < N

Translation:
You have a 3x3 matrix (A). It's transpose is a 3x3 matrix (T) such that
1
2
3
4
//pseudo code
for( i = 0 .. 2 )
  for( j = 0 .. 2 )
    T[j][i] = A[i][j]
Yes I am sure that is the .exe assignment maybe the prof got mixed up while coding so instead of inverted it is transpose.

For my input I have so far


for (line =0; line <= 2; line++)
{
Cout << "Enter the line" << line+1
<< "of the row << row+1 << ": ";
cin >> value [line][row]
}

Would i be storing the values correctly?
closed account (D80DSL3A)
Not quite. If the user enters:
1 2 3
for each line (where the spaces are needed between the values).
Then the following should work:
1
2
3
4
5
6
for (line =0; line <= 2; line++)
{
cout << "Enter the line" << line+1;// I corrected 2 syntax errors on this line
<< "of the row "<< line+1 << ": ";// right? line is actually the row# (more errors were on this line)
cin >> value[line][0] >> value[line][1] >> value[line][2];// reading all 3 values from one line of input.
}

Please compile and test your own code. You should be catching these basic syntax errors yourself.
Last edited on
Topic archived. No new replies allowed.