0% found this document useful (0 votes)
42 views8 pages

Name: Muhamad Junaid CMS: 1765-2020 Section: B Program: BS Computer Science

This document contains information about a student named Muhamad Junaid enrolled in the BS Computer Science program at CMS 1765-2020 in Section B. It also includes two C++ code snippets, the first for adding two 2D arrays and displaying the sum, and the second for sorting an array in ascending order.

Uploaded by

Hassan Farid
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)
42 views8 pages

Name: Muhamad Junaid CMS: 1765-2020 Section: B Program: BS Computer Science

This document contains information about a student named Muhamad Junaid enrolled in the BS Computer Science program at CMS 1765-2020 in Section B. It also includes two C++ code snippets, the first for adding two 2D arrays and displaying the sum, and the second for sorting an array in ascending order.

Uploaded by

Hassan Farid
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

Name: Muhamad Junaid

CMS: 1765-2020
Section: B
Program: BS Computer Science

Q1:
#include<iostream>

using namespace std;

#include<cmath>

main()

int r=2;

int c=2;

int i,j;

int a[100][100],b[100][100];

int sum[100][100];

// First matrix

cout<<"\tFirst Matrix"<<endl;

cout<<"\n";

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

for( j=0;j<c;++j )

cout<<"Enter the value in Row:"<<i+1;

cout<<" column:"<<j+1<<":";

cin>>a[i][j];

}
Name: Muhamad Junaid
CMS: 1765-2020
Section: B
Program: BS Computer Science

cout<<"\n";

// second matrix

cout<<"\t Second Matrix"<<endl;

cout<<"\n";

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

for( j=0;j<c;++j )

cout<<"Enter the value in Row:"<<i+1;

cout<<" Column:"<<j+1<<":";

cin>>b[i][j];

cout<<"\n";

cout<<"\t First 2x2 Matrix"<<endl;

cout<<"\n";
Name: Muhamad Junaid
CMS: 1765-2020
Section: B
Program: BS Computer Science

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

for( j=0;j<c;j++ )

cout<< a[i][j]<<" ";

cout<<endl;

cout<<"\n";

cout<<"\t Second 2x2 Matrix"<<endl;

cout<<"\n";

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

for( j=0;j<c;j++ )

cout<< b[i][j]<<" ";

cout<<endl;

// For sum

for(i=0;i<r;++i)
Name: Muhamad Junaid
CMS: 1765-2020
Section: B
Program: BS Computer Science

for(j=0;j<c;++j)

sum[i][j]=a[i][j]+b[i][j];

cout<<"\n";

cout<<"Sum"<<endl;

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

for(j=0;j<c;++j)

cout<<sum[i][j]<<" ";

if(j==c-1)

cout<<endl;

}
Name: Muhamad Junaid
CMS: 1765-2020
Section: B
Program: BS Computer Science

Q2:
#include<iostream>

using namespace std;

main()

int arr[50];

int i,j,size,temp;

cout<<"Enter the size of array=";

cin>>size;

cout<<"\n";

cout<<"Enter the Number in Array"<<endl;

cout<<"\n";

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

cout<<"Enter the number=";


Name: Muhamad Junaid
CMS: 1765-2020
Section: B
Program: BS Computer Science

cin>>arr[i];

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

for( j=i+1;j<size;j++ )

if(arr[j]<arr[i])

temp=arr[i];

arr[i]=arr[j];

arr[j]=temp;

cout<<"\n";

cout<<"Elements of array sorted in ascending order:"<<endl;


Name: Muhamad Junaid
CMS: 1765-2020
Section: B
Program: BS Computer Science

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

cout<<arr[i]<<endl;

}
Name: Muhamad Junaid
CMS: 1765-2020
Section: B
Program: BS Computer Science

You might also like