The document defines a function to print the upper triangular items of a 2D array. It then declares a 3x3 integer array, takes user input to populate it, and calls several functions to print: the original 2D array, even items, sum of even items, main diagonal items, and upper triangular items by calling the defined function.
The document defines a function to print the upper triangular items of a 2D array. It then declares a 3x3 integer array, takes user input to populate it, and calls several functions to print: the original 2D array, even items, sum of even items, main diagonal items, and upper triangular items by calling the defined function.
The document defines a function to print the upper triangular items of a 2D array. It then declares a 3x3 integer array, takes user input to populate it, and calls several functions to print: the original 2D array, even items, sum of even items, main diagonal items, and upper triangular items by calling the defined function.
void Upitems(int M[3][3]) { cout << "\n____________________________ down items in 2Dim Array_______________\n\n";
for (int i = 0; i < 3; i++)
{ cout << "\n";
for (int j = 0; j < 3; j++)
{ if (i > j) cout << M[i][j] << "\t"; else cout << "0" << "\t"; } } } int main() { cout << "_______________________ Ex1____________________\n\n\n"; int M[3][3]; for (int i = 0; i < 3; i++) { cout << "________________ Row[" << i << "]________________\n"; for (int j = 0; j < 3; j++) { cout << "M[" << i << "][" << j << "] : "; cin >> M[i][j]; } } cout << "\n ______________________ 2Dim Array items ________________\n\n"; for (int i = 0; i < 3; i++) { cout << "\n";
for (int j = 0; j < 3; j++)
{ cout<<M[i][j]<<"\t"; } } cout << "\n____________________________ Even items in 2Dim Array_______________\n\n";
for (int i = 0; i < 3; i++)
{ //cout << "\n";
for (int j = 0; j < 3; j++)
{ if(M[i][j]%2==0) cout << M[i][j] << "\t"; } } cout << "\n___________________ Sum items in 2Dim Array_______________\n"; int sum = 0; for(int i=0;i<3;i++) for (int j = 0; j < 3; j++) { if(M[i][j]%2==0) sum += M[i][j]; } cout << "The sum is : " << sum << endl; cout << "\n____________________________ Main items in 2Dim Array_______________\n\n";
for (int i = 0; i < 3; i++)
{ cout << "\n";
for (int j = 0; j < 3; j++)
{ if (i == j) cout << M[i][j] << "\t"; else cout << "0"<<"\t"; } } cout << "\n____________________________ Up items in 2Dim Array_______________\n\n";
for (int i = 0; i < 3; i++)
{ cout << "\n";
for (int j = 0; j < 3; j++)
{ if (i < j) cout << M[i][j] << "\t"; else cout << "0" << "\t"; } } Upitems(M);