Professional Documents
Culture Documents
Semester : BS CS – 1A
Name : Muhammad Zain
Enroll no : (02-134182-037)
Exercise 1
Write a C++ Program that computes the sum of two matrices. Each matrix is of 2 rows and 2
columns and will be created from user input.
SOURCE CODE:
#include<iostream>
using namespace std;
int main()
{
int a1[2][2],a2[2][2],a3[2][2];
for(int i=0;i<2;i++)
)
{
for(int j=0;j<2;j++)
{
cout<<"enter "<<"["<<i*1<<"]["<<j*1<<"]"<< " of matrix A"<<": ";
cin>>a1[i][j];
}
}
//cout to give distance between matix A and B
cout<<"\n\n\n";
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
cout<<"enter "<<"["<<i*1<<"]["<<j*1<<"]"<< " of matrix B"<<": ";
cin>>a2[i][j];
}
}
cout<<"\n\n\n";
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
//cout<<"enter "<<"["<<i*1<<"]["<<j*1<<"]"<< " of matrix B"<<": ";
a3[i][j]=a1[i][j]+a2[i][j];
}
}
return 0;
OUTPUT
Exercise 2
Write a C++ program to calculate the result of three sections of a semester. Following are the rules for
result:
1. Three are 3 sections.
2. Each section has 8 students.
3. Each student takes 5 courses.
Marks for each subject of every student of each section must be taken from the user.
Source code
#nclude<iostream>
Using namespace std;
int main()
{
float a1[5][8],a2[8][5],a3[8][5];
for(int i=0;i<8;i++)
{
cout<<"\n\n";
for(int j=0;j<5;j++)
{
cout<<"enter marks of "<<j+1<<" subject of student "<<i+1<<":"<<" ";
cin>>a1[i][j];
}
}
for(int i=0;i<8;i++)
{
cout<<"\n\n";
for(int j=0;j<5;j++)
{
Department of computer science Semester BSCS-1A
CSL-113: Computer Programming Lab Lab 07:Array(Multi-dimentional)
CSL-113 : Computer Programming Lab
Semester : BS CS – 1A
Name : Muhammad Zain
Enroll no : (02-134182-037)
for(int i=0;i<8;i++)
{
cout<<"\n\n";
for(int j=0;j<5;j++)
{
cout<<"enter marks of "<<j+1<<" subject of student "<<i+1<<":"<<" ";
cin>>a3[i][j];
}
}
cout<<"\n\n";
cout<<"OBTAIND MARKS OF STUDENTS ARE";
return 0;
}
Output
Exercise 3
Write a C++ program, that read 12 integer values from user, store values in Matrix of 4 X 3. Create
another Matrix of 4 X 3, divide each element of Matrix1 by five, and store the result in the Matrix2.
Source code
#include<iostream>
using namespace std;
int main()
{
float a1[4][3],a2[4][3];
for(int i=0;i<4;i++)
{
for(int j=0;j<3;j++)
{
cout<<"enter value of row "<<i+1<<" and column "<<j+1<<" : ";
cin>>a1[i][j];
}
}
for(int i=0;i<4;i++)
{
for(int j=0;j<3;j++)
{
a2[i][j]=a1[i][j]/5;
}
}
return 0;
}
Output