# Need help in Matrix Addition & finding Inverse of a Matrix

This is a discussion on Need help in Matrix Addition & finding Inverse of a Matrix within the C Programming forums, part of the General Programming Boards category; Dear All, Am a beginner in C programming & I have following two tough programs as a part of my ...

1. ## Need help in Matrix Addition & finding Inverse of a Matrix

Dear All,

Am a beginner in C programming & I have following two tough programs as a part of my self training.

1. In a single-dimensional matrix, I want to add the elements of each row & elements of each column separately & then I have to print the result in the last column & in the last row. For example, If I got 3 rows & 3 columns, I want to print the sum of row elements in the 4 th column for each row & sum of column elements in the 4th row for each column. How can I accomplish this?

2. In a single dimensional matrix, I have to reverse the second row elements alone & I have to print the result in the result matrix. How can I accomplish this?

I request someone to reply at the earliest. I have been trying to solve this for the past 2 days. But am unable to solve it.

2. 1. You can add up a row or a column with a loop. Then, since you need to add up every row/column, you need to put that loop inside a loop.

2. Ignore the matrix part. Do you know how to reverse a single-dimensional array?

3. Originally Posted by ssatyan.129
Dear All,

If I got 3 rows & 3 columns, I want to print the sum of row elements in the 4 th column for each row & sum of column elements in the 4th row for each column.
max size 3 => you want to print up to 4th => kinda weird !

Originally Posted by ssatyan.129
In a single dimensional matrix, I have to reverse the second row elements alone
symmetrically swap.
first <=> last , second <=> pre-last ...

4. Originally Posted by ssatyan.129
2. In a single dimensional matrix, I have to reverse the second row elements alone & I have to print the result in the result matrix. How can I accomplish this?
What does it mean to reverse the second row elements? Print them in reverse order? Print the second row of the inverse of the matrix?

If you're not afraid to compute a lot of determinants, you may use Cramer's Rule to compute the inverse of a matrix, i.e. A^(-1) == adj(A)/det(A), where adj(A) is the adjugate matrix corresponding to A. Based on this rule, it shouldn't be hard to come up with a formula that computes the value of a single arbitrary element (i,j) of the inverse. There are better methods available, and I know that I have once been reading about them in my book on numerical math, but I don't remember any.

Greets,
Philip

5. symmetrically swap.
first <=> last , second <=> pre-last ...
Vocab word of day: penultimate

6. You keep saying "In a single-dimensional matrix" but you are in fact talking about a 2 dimensional matrix (rows and columns).

No, Snafuist. He's not talking about inverse. Just reverse 2nd row elements array[ R, WIDTH - C]

To start with, create a result matrix of dimensions rows+1 and cols+1 to allow for holding extra row and column for sums.

1) Move the values into this new matrix.
2) Loop accoss all rows to fill in row totals into last column.
3) Loop across all columns to fill in column total in last row.
4) Reverse the order of row #2's values.

Popular pages Recent additions