Prac

You might also like

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

#include<iostream>

using namespace std;


int main(){
int rsize,csize,i,j;
//GET BOTH ROW SIZE AND COL SIZE AT THE SAME COUT
cout<<"Enter number of Rows and Columns: " ;
cin>>rsize;
cin>>csize;
int array1[rsize][csize];
int array2[rsize][csize];
int array3[rsize][csize];

//FIRST 2D ARRAY
cout<<"\nRow 1\n";
for(i=0;i<rsize;i++){
for(j=0;j<csize;j++){
cin>>array1[i][j];
} // baby loop
} // mother loop

//2ND 2D ARRAY
cout<<"\nRow 2\n";
for(i=0;i<rsize;i++){
for(j=0;j<csize;j++){
cin>>array2[i][j];
} // baby loop
} // mother loop

/*==============================
COMBINATION OF THOSE ARRAYS
CALLED ARRAY3
FORMULA:
Array3 = Array1 + Array2
==============================*/

cout<<"\nSummary of Table 1 and Table 2\n";


for(i=0;i<rsize;i++){
for(j=0;j<csize;j++){
array3[i][j]=array1[i][j]+array2[i][j];
cout<<"["<<i<<"]"<<"["<<j<<"]"<<array3[i][j]<<" ";
} // baby loop
cout<<endl;
} // mother loop

/*==============================
FINDING THE LARGEST ELEMENT
IN ARRAY1
*Line 13 - 19*
==============================*/

int largest=array1[0][0];
cout<<"\nLargest element in Row 1: ";
for(i=0;i<rsize;i++){
for(j=0;j<csize;j++){
if(array1[i][j]>largest){
largest=array1[i][j];
} // if statement
} // baby loop
}// mother loop
cout<<largest<<endl;

/*==============================
FINDING THE LARGEST ELEEMNT
IN ARRAY2
*Line 21 - 27*
==============================*/
largest=array2[0][0];
cout<<"Largest element in Row 2: ";
for(i=0;i<rsize;i++){
for(j=0;j<csize;j++){
if(array2[i][j]>largest){
largest=array2[i][j];
} // if statement
} // baby loop
}// mother loop
cout<<largest<<endl;
return 0;}

You might also like