0% found this document useful (0 votes)
24 views

PF 2 Assignment

The document is an assignment to add two matrices of the same size by taking input from the user for the number of rows and columns of the matrices. It then takes input for the values of both matrices and stores them in arrays. It iterates through the arrays to add the corresponding elements of both matrices and stores them in a third sum array. Finally, it prints the sum matrix.

Uploaded by

Radey32167
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

PF 2 Assignment

The document is an assignment to add two matrices of the same size by taking input from the user for the number of rows and columns of the matrices. It then takes input for the values of both matrices and stores them in arrays. It iterates through the arrays to add the corresponding elements of both matrices and stores them in a third sum array. Finally, it prints the sum matrix.

Uploaded by

Radey32167
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment

Name: Husnain Sarfraz

Sap Id: 70067973

Section: (S)

Subject: PF - 2
Q1. Take the size of two matrices from user. Input value of both matrices from
user. For addition the size of both matrices must be same. Take the value of
both the matrices and add them store and display the result in a third matrix.

#include <iostream>
using namespace std;
int main()
{
int r, c, a[50][50], b[50][50], sum[50][50], i, j;
cout << "Enter rows = ";
cin >> r;
cout << "Enter columns = ";
cin >> c;
cout << endl <<"Elements of 1st matrix " << endl;

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


for(j = 0; j < c; ++j)
{
cout << "Enter element a" << i + 1 << j + 1 << " : ";
cin >> a[i][j];
}

cout << endl << "Elements of 2nd matrix " << endl;
for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout <<"Enter element b" << i + 1 << j + 1 << " : ";
cin >> b[i][j];
}

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


for(j = 0; j < c; ++j)
sum[i][j] = a[i][j] + b[i][j];

cout << endl <<"Sum of two matrix is " << endl;


for(i = 0; i < r; ++i)
for(j = 0; j < c; ++j)
{
cout << sum[i][j] << " ";
if(j == c - 1)
cout << endl;
}
return 0;
}

You might also like