100% found this document useful (1 vote)
291 views

Matrix Addition: Courtesy Ms. P. Chitra, Assistant Professor

The document describes a program to perform matrix addition. It explains that the program takes the row and column sizes of two matrices as input, then inputs the elements of each matrix. It adds the corresponding elements of the two matrices and stores the results in a third matrix. Finally, it prints out the summed matrix. The algorithm uses nested for loops to iterate through the matrices element-by-element and add them to the corresponding element in the output matrix.

Uploaded by

mani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
291 views

Matrix Addition: Courtesy Ms. P. Chitra, Assistant Professor

The document describes a program to perform matrix addition. It explains that the program takes the row and column sizes of two matrices as input, then inputs the elements of each matrix. It adds the corresponding elements of the two matrices and stores the results in a third matrix. Finally, it prints out the summed matrix. The algorithm uses nested for loops to iterate through the matrices element-by-element and add them to the corresponding element in the output matrix.

Uploaded by

mani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MATRIX ADDITION

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.

Courtesy Ms. P. Chitra, Assistant Professor

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

Courtesy Ms. P. Chitra, Assistant Professor

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

The elements of B matrix


1 2 3
4 5 6
7 8 9
The addition of two matrixes
2

10

12

14

16

18

RESULT:
Courtesy Ms. P. Chitra, Assistant Professor

Page 4

MATRIX ADDITION

The program is executed and the output is verified.

Courtesy Ms. P. Chitra, Assistant Professor

Page 5

You might also like