Name Roll Number Section Submitted To Date: Muhammad Haseeb Ahsan 16F-8351 A1 Sir Shahi Dost 09/12/2016

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Name Muhammad Haseeb Ahsan

Roll Number 16F-8351

Section A1

Submitted to Sir Shahi Dost

Date 09/12/2016
Assignments in LAB…
Task 1
#include<iostream>
using namespace std;
void main()
{
int const row = 5;
int const col = 4;
int arr[row][col];
int start = 100;
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
arr[i][j] = start;
cout<<start<<"\t";
start++;
}
cout<<endl;
}
system("pause");
}
Task 2
#include<iostream>
using namespace std;
void arrayfun(int[][3],int );
void main()
{
int c[10][3];
int const d=10;
arrayfun(c,d);
system("pause");
}
void arrayfun(int a[][3],int size)
{
size=10;
int const row = 5;
int const col = 4;
int arr[row][col];
int start = 100;
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
arr[i][j] = start;
cout<<start<<"\t";
start++;
}
cout<<endl;
}
}
Lab Tasks
Task 1
#include<iostream>
using namespace std;
void arrfun(int arr[5][4],int row,int col);
void main()
{
int start=1;
int const row=5;
int const col=4;
int arr[row][col];
int i=0;
while( i<row)
{
int j=0;
while (j<col)
{
arr[i][j]=start;
start++;
j++;
}
i++;
}
arrfun(arr,row,col);
system("pause");
}
void arrfun(int arr[5][4],int row,int col)
{
int rowsum=0;
int colsum=0;
int sum=0;
cout<<" The Matrix A ="<<endl;
int i=0;
while(i < row)
{
int j=0;
while(j < col)
{
sum = sum + arr[i][j];
cout<<" "<<arr[i][j]<<"\t";
j++;
}
i++;
cout<<endl<<endl;

}
cout<<endl;
cout<<"Sum of All Elements of ARRAY = "<<sum<<endl;
cout<<endl;
cout<<"Row-wise Sum of Element of Array ="<<endl;
int k=0;
while(k < row)
{
rowsum=0;
int l=0;
while(l < col)
{
rowsum=rowsum+arr[k][l];
l++;
}
cout<<"Sum of element of "<<k<<"th row = "<<rowsum<<endl;
k++;
}
cout<<endl;
cout<<"Coloumn-wise Sum of Element of Array"<<endl;
int h=0;
while(h < col)
{
colsum=0;
int g=0;
while(g < row)
{
colsum=colsum+arr[g][h];
g++;
}
cout<<"Sum of element of "<<h<<"th column = "<<colsum<<endl;
h++;
}
cout<<endl;
cout<<" TRANSPOSE(A) = "<<endl;
int d=0;
while(d < col)
{
int s=0;
while(s<row)
{
if(d == 1 && s == 0)
{
cout<<" "<<arr[s][d]<<"\t";
}
else
{
cout<<" "<<arr[s][d]<<"\t";
}
s++;
}
cout<<endl<<endl;
d++;
}
}
Task 2
#include<iostream>
using namespace std;
void main()
{
int const row = 3;
int const col = 3;
int arr[row][col];
int tra[row][col];
int start = 1;
cout<<" Matrix A = \n";
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
arr[i][j] = start;
cout<<"\t"<<start;
start++;
}
cout<<endl<<endl;
}
cout<<endl;
cout<<endl;
start = 1;
cout<<"Matrix B (Transpose) = \n";
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
tra[j][i]=arr[i][j];
}
}
for(int i=0;i<col;i++)
{
for(int j=0;j<row;j++)
{
cout<< "\t"<<tra[i][j];
}
cout<<endl<<endl;
}
cout<<"Matrix B (Diognal) = \n";
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
if(i == j)
cout<<"\t"<<arr[i][j];
else
{
cout<<"\t";
}
}
cout<<endl<<endl;
}
system("pause");
}
Task 3
#include<iostream>
using namespace std;
void lowerhalf(int[][5],int );
void main()
{
int c[5][5];
int const d=5;
cout<<"Matrix = \n";
int i,j;
for (i=0;i<5;i++ )
{
for(j=0;j<5;j++ )
{
c[i][j]= rand() % 10;
cout<<"\t"<<c[i][j];
}
cout<<endl<<endl;
}
cout<<endl;
cout<<endl;
lowerhalf(c,d);
system("pause");
}
void lowerhalf(int arr[][5], int size)
{
size = 5;
cout<<"Lower Diognals = \n";
int i,j;
for (i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if (i > j)
{
cout<<"\t"<<arr[i][j];
}
else
{
cout<<" ";
}
}
cout<<endl<<endl;
}
}
Task 4
#include<iostream>
using namespace std;
void upperhalf(int[][5],int );
void main()
{
int c[5][5];
int const d=5;
cout<<"Matrix = \n";
int i,j;
for (i=0;i<5;i++ )
{
for(j=0;j<5;j++ )
{
c[i][j]= rand() % 10;
cout<<"\t"<<c[i][j];
}
cout<<endl<<endl;
}
cout<<endl;
cout<<endl;
upperhalf(c,d);
system("pause");
}
void upperhalf(int arr[][5], int size)
{
size = 5;
cout<<"Upper Diognals = \n";
int i,j;
for (i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if (i > j)
{
cout<<"\t";
}
else
{
cout<<"\t"<<arr[i][j];

}
}
cout<<endl<<endl;
}
}

You might also like