Matrix Addition: Courtesy Ms. P. Chitra, Assistant Professor
Matrix Addition: Courtesy Ms. P. Chitra, Assistant Professor
EX. NO :
DATE
:
MATRIX ADDITION
AIM:
To write a program to perform matrix addition.
ALGORITHM:
Step-1 Start the program.
Step-2 Enter the row and column of the matrix.
Step-3 Enter the elements of the a matrix.
Step-4 Enter the elements of the b matrix.
Step-5 Print the a matrix in the matrix form.
Step-6 Print the b matrix in the matrix form.
Step-7 Set a loop up to the row.
Step-8 Set a inner loop up to the column
Step-9 Add the elements of a and b in column wise and store the result in c matrix.
Step-10 After the execution of the two loops. Print the value oh c matrix.
Step-11 Stop.
PSEUDOCODE:
1.
2.
3.
4.
5.
6.
7.
BEGIN the program by entering the row and column of the matrix.
ENTER the elements of a and b matrix.
PRINT the a and b matrix in matrix form.
SET a loop up to row and inner loop up to column.
ADD the elements of a and b in column wise and store the value the result in c matrix.
PRINT the value of c matrix.
TERMINATE the program.
Page 1
MATRIX ADDITION
FLOW CHART
start
Start
for i = 0 to n
Read m,n
Print(\n)
for i = 0 to m
for j = 0 to n
for j = 0 to n
c[i][j] = a[i][j] + b[i][j]
Read a[i][j]
Read b[i][j]
Print c[i][j]
Stop
A
Page 2
MATRIX ADDITION
PROGRAM
#include<stdio.h>
#include<conio.h>
main()
{
int a[25][25],b[25][25], c[25][25], I, j m, n;
clrscr();
printf(\n Enter the rows and columns of two matrixes );
scanf(%d %d , &m, &n)
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf(%d,&a[i][j]);
}
printf{\n Enter the elements of B matrix);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf(%d, &b[i][j]);
}
printf(\n The elements of A matrix);
for(i=0;i<m;i++)
{
printf(\n);
for(j=0;j<n;j++)
printf(\t %d, a[i][j]);
}
printf(\n The elements of B matrix);
for(i=0;i<m;i++)
{
printf(\n);
for(j=0;j<n;j++)
printf(\t %d,b[i][j]);
}
printf(\n The addition of two matrices);
Courtesy Ms. P. Chitra, Assistant Professor
Page 3
MATRIX ADDITION
for(i=0;i<m;i++)
{
printf(\n);
for(j=0;j<n;j++)
{
c[i][j]=a[i][j] + b[i][j];
printf(\t %d,c[i][j]);
}}
getch();
}
OUTPUT:
Enter the rows and columns of two matrices. 3 3
Enter the elements of A matrix 1 2 3 4 5 6 7 8 9
Enter the elements of B matrix 1 2 3 4 5 6 7 8 9
The elements of A matrix
1 2
10
12
14
16
18
RESULT:
Courtesy Ms. P. Chitra, Assistant Professor
Page 4
MATRIX ADDITION
Page 5