Anda di halaman 1dari 6

Saad Mehmood Rashid Lab 03

#include<iostream>

using namespace std;

int main()

{ int a[3][2];

int b[2][3];

int mul[3][3];

cout<<" Enter the elements of first array"<<endl;

for(int i=0; i<3; i++)

{ for(int j=0; j<2; j++)

cin>>a[i][j];

} }

cout<<"Enter the elements of second array"<<endl;

for(int i=0; i<2; i++)

{ for(int j=0; j<3; j++)

{ cin>>b[i][j];

} for(int i=0; i<3; i++)

{ for(int j=0; j<3; j++)

{ int sum=0;

for(int k=0; k<3; k++)

{ sum=sum+ a[i][k] * b[k][j];

mul[i][j] = sum;}

cout<< endl << "product of two arrays are : "<<endl;

for(int i=0; i<3; i++)

for(int j=0; j<3; j++)

cout<<mul[i][j]<<" ";
Saad Mehmood Rashid Lab 03

cout<<endl;

system(" pause"); return 0;}

Task 02
#include<iostream>

using namespace std;

int main()

{ int counter,arr[100],integer;

cout<<"How many integers you want to enter ? "<< endl;

cin>>counter;

for(int i=0; i<counter; i++)

{ cout<<" Enter integer :"<< i+1 << " " << endl; cin>>arr[i];

cout<<"Enter the integer that you want to search:";

cin>>integer;

int first =0;

int last = counter-1;

int middle = (first+last)/2;

while (first<=last)

{ if(arr[middle]<integer)
Saad Mehmood Rashid Lab 03

{ first = middle+1;}

else if(arr[middle]==integer)

{ cout<<integer<<"Found in the array at the location"<<middle+1<<"\n";

break;

else{ last=middle-1;}

middle=(first+last)/2;}

if(first>last)

cout<<integer<<" Sorry we did not find it in the array";

system("pause");

return 0;

Task 03
#include<iostream>

using namespace std;

int main()

{ int a[75],dlt,ac;

int j, b[20];

cout<<"How many element of array you want to create : ? "<< endl;

cin>>ac;

cout<<" \n Enter the elements of array : \n";

for(int i=0; i<ac; i++)


Saad Mehmood Rashid Lab 03

{ cin>>a[i];}

cout<<"\n Enter element to delete:";

cin>>dlt;

for(int i=0; i<ac; i++)

{ if(a[i]!=dlt)

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

if(j==ac)

{ cout<<"\n Sorry element is not found in the Array : "; exit(0); }

else

{ cout<<"\n New array is : "<< endl; for(int i=0; i<j; i++) {

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

system(" pause");

return 0;}

Task 05

#include<iostream>

using namespace std;

int main(){

int a [15][15] ,b[15][15], mul[15][15];

int R1,R2,C1,C2;

cout<<" Enter first Matrix Rows and columns :"<< endl;

cin>>R1;

cin>>C1;
Saad Mehmood Rashid Lab 03

cout<<" Enter Second Matrix Rows and columns :"<< endl;

cin>>R2;

cin>>C2

while ( C1!=R2){cout<<" Error !!!! Column of first matrix is not equal to Row of second ";

cout<< "Enter Rows and Columns of First Matrix : " ;

cin>>R1;

cin>> C2 ;cout<< "Enter Rows and Columns of Second Matrix : "

cin>>R2;

cin>> C2 ;}

cout<< " Enter elements of matrix 1 : "<<endl;

for (int i=0; i<R1 ; i++){

for (int j=0; j<C1 ; j++){cout<< "Enter element a "<<"Row " << i+1<< " Column " << j+1<< " : "<< endl;

cin>>a[i][j];

}}cout<< " Enter elements of matrix 2 : "<<endl;

for (int i=0; i<R2 ; i++){

for (int j=0; j<C2 ; j++){

cout<< "Enter element a " << "Row " << i+1<< " Column " << j+1<< " : "<< endl;

cin>>b[i][j];}

for (int i=0; i<R1; i++)

for (int j=0; j<C2 ; j++){mul[i][j]=0;}for (int i=0; i<R1; i++) for (int j=0; j<C2 ; j++) for (int k=0; k< C1;
k++){mul[i][j]+=a[i][j]*b[k][j]; }

cout<< endl << "Output Matrix" << endl;

for (int i=0; i<R1; i++)

for (int j=0; j<C2 ; j++){

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

if ( j== C2-1 )

cout<<endl;}

system ("pause");
Saad Mehmood Rashid Lab 03

return 0;

Anda mungkin juga menyukai