Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
19 views

Program To Add Two Matrices

The document contains a C program to add two matrices. It takes the number of rows and columns as input, then takes the elements of two matrices A and B as input. It prints the elements of A and B, adds the corresponding elements, and prints the resulting summed matrix C. The program uses nested for loops to iterate through the rows and columns of the matrices to read input elements, print matrices, and perform the addition element-wise to generate matrix C.

Uploaded by

Priya Mishra
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Program To Add Two Matrices

The document contains a C program to add two matrices. It takes the number of rows and columns as input, then takes the elements of two matrices A and B as input. It prints the elements of A and B, adds the corresponding elements, and prints the resulting summed matrix C. The program uses nested for loops to iterate through the rows and columns of the matrices to read input elements, print matrices, and perform the addition element-wise to generate matrix C.

Uploaded by

Priya Mishra
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

www.w3professors.

com

/***

Gursharan Singh Tatla

Program to Add Two Matrices

#include <stdio.h>
main()
{
int a[10][10], b[10][10], c[10][10], i, j, row, col;
printf("\nEnter number of rows and columns: ");
scanf("%d %d", &row, &col);
printf("\nEnter elements of Array A:\n");
for (i=0; i<row; i++)
for (j=0; j<col; j++)
scanf("%d", &a[i][j]);
printf("\nEnter elements of Array B:\n");
for (i=0; i<row; i++)
for (j=0; j<col; j++)
scanf("%d", &b[i][j]);
printf("\nElements of Matrix A:\n\n");
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
printf("\t%d", a[i][j]);
printf("\n\n");
}
printf("\nElements of Matrix B:\n\n");
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
printf("\t%d", b[i][j]);
printf("\n\n");
}

Page No. 1

***/

www.w3professors.com

Gursharan Singh Tatla

for (i=0; i<row; i++)


for (j=0; j<col; j++)
c[i][j] = a[i][j] + b[i][j];
printf("\nMatrix Addition is:\n\n");
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
printf("\t%d", c[i][j]);
printf("\n");
}
getch();
}

Page No. 2

You might also like