|
Here is the
program to find the sum of the two integer matrices. The program
asks for the order (M, N) of the matrices. Soon after entering
the order, the cursor takes to the proper position in the screen
to input the matrices. User need to hit 'Enter' button after
each entry.
Logic : The logic applied here is very simple,
that what we do in the paper. The first entry of the first matrix ( A[1,1]
) is added up with the first entry of the second Matrix (B[1,1]) and
stored as the first member of the resultant matrix (C[1,1]). The procedure is
continued till the last number of the matrices.
The procedure can be modified slightly with the same
algorithm, to subtract,
multiply, or
transpose etc. |
|
|
|
#include<stdio.h>
void main()
{
int A[5][5], B[5][5], C[5][5], i, j, m, n;
clrscr();
printf("\n\n\t ENTER A ORDER OF THE MATRICES M,N...:
");
scanf("%d,%d", &m, &n);
printf("\n\n\t ENTER THE ELEMENTS OF THE FIRST
MATRIX..:\n\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
gotoxy(25+j*4,12+i*2);
scanf("%d",&A[i][j]);
}
printf("\n");
}
printf("\n\t ENTER THE ELEMENTS OF THE SECOND
MATRIX..:\n\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
gotoxy(25+j*4,18+m+i*2);
scanf("%d",&B[i][j]);
}
printf("\n");
}
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
C[i][j] = A[i][j] + B[i][j];
printf("\n\t THE SUM OF TWO MATRICES IS...:\n\n\t\t\t
");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
printf(" %d",C[i][j]);
printf("\n\n\t\t\t
");
}
getch();
}
Download exe and source code here.
Related source codes :
To find the difference of
two matrices
To multiply two matrices
To find the sum of primary
diagonal of a matrix
To find the sum of
secondary diagonal of a matrix
To find the transpose of
a matrix
Select program from the list |