0% found this document useful (0 votes)
26 views3 pages

Program 2

The program takes input for the number of rows and columns of two matrices from the user. It then takes input for the elements of the two matrices and calculates the sum of corresponding elements, storing them in a third 'sum' matrix. Finally, it prints out the sum matrix containing the element-wise sum of the two input matrices.

Uploaded by

Utkarsh Upadhyay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Program 2

The program takes input for the number of rows and columns of two matrices from the user. It then takes input for the elements of the two matrices and calculates the sum of corresponding elements, storing them in a third 'sum' matrix. Finally, it prints out the sum matrix containing the element-wise sum of the two input matrices.

Uploaded by

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

PROGRAM-2

WRITE A PROGRAM TO PRINT THE SUM OF TWO


MATRICES.

#include <stdio.h>
#include <conio.h>

int main()
{
int i,j,rows,col;
printf("Enter number of rows\n");
scanf("%d", &rows);
printf("Enter number of columns\n");
scanf("%d", &col);

int
a1[rows][col],a2[rows][col],sum[rows][col];

// Taking input for first matrix.


printf("Enter matrix 1\n");
for(i=0; i<rows; i++)
{
for(j=0; j<col; j++)
{
scanf("%d", &a1[i][j]);
}
}

// Taking input for second matrix.


printf("Enter matrix 2\n");
for(i=0; i<rows; i++)
{
for(j=0; j<col; j++)
{
scanf("%d", &a2[i][j]);
}
}

// Addition of matrix.
for(i=0; i<rows; i++)
{
for(j=0; j<col; j++)
{
sum[i][j] = a1[i][j] + a2[i][j];
}
}

// Sum of two matrices.


printf("Sum of two matrices.\n");
for(i=0; i<rows; i++)
{
for(j=0; j<col; j++)
{
printf("%d\t", sum[i][j]);
}
printf("\n");
}

return 0;
}
OUTPUT – 2

You might also like