This program adds two square matrices - Algorithm 1-3, Page 35.
Change it to implement the generalized algorithm to add two m x n
matrices.
Matrices, in general, are not square or n x n (n-by-n). The number of
rows may not be the same as the number of columns. Here is an example of
3 x 4 matrix.
2 3 1 0
1 4 2 -1
0 -2 2 3
You are asked to change that function so that it can add any two general
matrices, of the same dimensions.
5 1874
This program adds two square matrices - Algorithm 1-3, Page 35.
Change it to implement the generalized algorithm to add two m x n
matrices.
Matrices, in general, are not square or n x n (n-by-n). The number of
rows may not be the same as the number of columns. Here is an example of
3 x 4 matrix.
2 3 1 0
1 4 2 -1
0 -2 2 3
You are asked to change that function so that it can add any two general
matrices, of the same dimensions.
Did you read the page that was provided?
Did you read the page that was provided?
Yeah, let me post it. -
-
#include <stdio.h>
-
#include <stdlib.h>
-
-
#define SIZE 10
-
-
void addMatrix( int m1[][SIZE],
-
int m2[][SIZE],
-
int size,
-
int m3[][SIZE] );
-
-
void printMatrix( int m[][SIZE], int size );
-
-
int main ( void )
-
{
-
int size = 3;
-
int m1[SIZE][SIZE] =
-
{
-
{ 2, 0, 5 },
-
{ 3, 1, 10 },
-
{ 0, 4, 1 }
-
};
-
-
int m2[SIZE][SIZE] =
-
{
-
{ 0, 1, 3},
-
{ 2, 0, 1},
-
{ 6, 1, 8}
-
};
-
-
int m3[SIZE][SIZE];
-
-
addMatrix( m1, m2, size, m3 );
-
-
printf( "\nAdd two matrices:\n" );
-
printf( "\nMatrix 1: \n" );
-
printMatrix( m1, size );
-
printf( "\nMatrix 2: \n" );
-
printMatrix( m2, size );
-
printf( "\nTheir sum: \n" );
-
printMatrix( m3, size );
-
-
return 0;
-
}
-
-
/* ================== addMatrix ==================
-
Add m1 and m2, and place results in m3
-
Pre: m1 and m2 have data;
-
size - the number of columns and rows
-
Post: matrices added, result in m3
-
Return: nothing
-
*/
-
void addMatrix( int m1[][SIZE],
-
int m2[][SIZE],
-
int size,
-
int m3[][SIZE] )
-
{
-
int r;
-
int c;
-
-
for( r = 0; r < size; r++ )
-
for( c = 0; c < size; c++ )
-
m3[r][c] = m1[r][c] + m2[r][c];
-
-
return;
-
} /* addMatrix */
-
-
/* ================== printMatrix ================
-
Print matrix
-
Pre: m has data;
-
size - the number of columns and rows
-
Post: matrix m printed
-
Return: nothing
-
*/
-
void printMatrix( int m[][SIZE], int size )
-
{
-
int r;
-
int c;
-
-
for( r = 0; r < size; r++ )
-
{
-
for( c = 0; c < size; c++ )
-
printf( "%5d ", m[r][c] );
-
printf( "\n" );
-
}
-
printf( "\n" );
-
-
return;
-
} /* printMatrix */
-
Did you read the page that was provided?
Opps, i don't have the book, but it just shows a picture from what I remember. Of two matrices being added and having a sum. Like my program above.
This program adds two square matrices - Algorithm 1-3, Page 35.
Change it to implement the generalized algorithm to add two m x n
matrices.
Matrices, in general, are not square or n x n (n-by-n). The number of
rows may not be the same as the number of columns. Here is an example of
3 x 4 matrix.
2 3 1 0
1 4 2 -1
0 -2 2 3
You are asked to change that function so that it can add any two general
matrices, of the same dimensions.
What exactly is your problem? Are you confused about Matrices, Matrix Addition, Implementing Matrix operations in code?
If you want to know about Matrices google them and you will find all the info you need.
If you have a coding issue ask a specific question. You will get a reply.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Nils Wagner |
last post by:
Hi all,
Has someone written a C binding to transfer matrices from C to Python
and vice versa ?
Any pointer would be appreciated.
Nils
|
by: bissatch |
last post by:
Hi,
I fully understand the purpose of an alt attribute within a <img> tag
but why would you use a title or summary attribute within, for example,
a <p> tag. I have read books recommending that I...
|
by: Prototipo |
last post by:
Hi! I need to dynamically create X vectors of matrices (with a known
size of 5x5). It's like a three-dimensional matrix with 2 known
dimensions and the third unknown.
I have something like:
...
|
by: Jason Huang |
last post by:
Hi,
Would someone explain the following coding more detail for me? What's the
( ) for?
CurrentText = (TextBox)e.Item.Cells.Controls;
Thanks.
Jason
|
by: Mark Ingram |
last post by:
Right, ive got the following array with which to setup a color matrix.
bm = 1; bm = 0; bm = 0; bm = 0; bm = 0;
bm = 0; bm = 1; bm = 0; bm = 0; bm = 0;
bm = 0; bm = 0; bm = 1; bm = 0; bm = 0;
bm...
|
by: emaghero |
last post by:
Does anybody know an algorithm for the fast multiplication of three n-x-n symmetric matrices?
I have an algorithm, which I'm not too pleased with, that does the job.
Does anybody know a faster...
|
by: tomamil |
last post by:
imagine that you have different matrices with different names and you
want to perform the same action with each of them. is it possible to
put their names into some array and to create a loop that...
|
by: td0g03 |
last post by:
Hello, I am new to C and I am new to English. I not sure what palindromes mean. I don't know exactly what my teacher wants me to do. If someone could explain it to me in a different way that would be...
|
by: debiasri |
last post by:
I have to devide a matrix in variable no of matrices with each having variable no of rows. Like I have to devide a matrix with dim.9X19 into say 4 matrices with row nos 1,6,6,6 respectively, and I...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |