EnochDuah 5 months ago
enochduah #homeworkhelp

Consider an integer 2D-array of size 6x6. The elements are taken as input from the user. Write a program to find those pair of elements

Consider an integer 2D-array of size 6x6. The elements are taken as input from the user. Write a program to find those pair of elements that has the maximum and minimum difference among all element pairs.

Here's the answer in code: #include <iostream>

#include <climits>

using namespace std;


int main() {

// Declare a 6x6 integer array

int arr[6][6];

// Variables to store the maximum and minimum differences

int maxDiff = INT_MIN;

int minDiff = INT_MAX;

// Variables to store the pairs with max and min differences

int maxDiffRow1 = 0, maxDiffCol1 = 0, maxDiffRow2 = 0, maxDiffCol2 = 0;

int minDiffRow1 = 0, minDiffCol1 = 0, minDiffRow2 = 0, minDiffCol2 = 0;

// Take input from the user

cout << "Enter the elements of the 6x6 array:" << endl;

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

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

cin >> arr[i][j];

}

}

// Find the maximum and minimum differences

for (int i1 = 0; i1 < 6; i1++) {

for (int j1 = 0; j1 < 6; j1++) {

for (int i2 = 0; i2 < 6; i2++) {

for (int j2 = 0; j2 < 6; j2++) {

// Skip if it's the same element

if (i1 == i2 && j1 == j2) {

continue;

}

// Calculate the absolute difference

int diff = abs(arr[i1][j1] - arr[i2][j2]);

// Update maximum difference

if (diff > maxDiff) {

maxDiff = diff;

maxDiffRow1 = i1;

maxDiffCol1 = j1;

maxDiffRow2 = i2;

maxDiffCol2 = j2;

}

// Update minimum difference

if (diff < minDiff) {

minDiff = diff;

minDiffRow1 = i1;

minDiffCol1 = j1;

minDiffRow2 = i2;

minDiffCol2 = j2;

}

}

}

}

}

// Output the results

cout << "Maximum difference: " << maxDiff << endl;

cout << "Elements with maximum difference: " << arr[maxDiffRow1][maxDiffCol1]

<< " at position (" << maxDiffRow1 << "," << maxDiffCol1 << ") and "

<< arr[maxDiffRow2][maxDiffCol2] << " at position ("

<< maxDiffRow2 << "," << maxDiffCol2 << ")" << endl;

cout << "Minimum difference: " << minDiff << endl;

cout << "Elements with minimum difference: " << arr[minDiffRow1][minDiffCol1]

<< " at position (" << minDiffRow1 << "," << minDiffCol1 << ") and "

<< arr[minDiffRow2][minDiffCol2] << " at position ("

<< minDiffRow2 << "," << minDiffCol2 << ")" << endl;

return 0;

}

0
370

square root of (7+24i)(24i-7)

square root of (7+24i)(24i-7)

1746135388.png
EnochDuah
5 months ago

Find the domain of the function. g(u) = √u + √4-u

Find the domain of the function. g(u) = √u + √4-u

1746135388.png
EnochDuah
5 months ago

What did the classified documents released by Edward Snowden reveal?Mu...

What did the classified documents released by Edward Snowden reveal?Multiple choice questi...

1746135388.png
EnochDuah
4 months ago
video

Bare Metal vs VMs vs Containers: Which Should You Choose?

enochduah
EnochDuah
4 months ago

The extracted text from the image is: “Write a statement that declare...

The extracted text from the image is: “Write a statement that declares a PrintWriter re...

1746135388.png
EnochDuah
4 months ago