Answer to Question #15917 in C++ for sakura

Question #15917
Using 2 dimensional array, find and display the lowest and highest value.
Example
Enter the number of rows: 3
Enter the number of columns: 2
Enter array values:
1
2
3
4
5
6
Display Array Elements
1 2
3 4
5 6
Highest: 6
Lowest: 1
Try Again (Y/N)?
1
Expert's answer
2012-10-04T10:23:20-0400
#include <iostream>
using namespace std;

int main(){
int m,n;
loop:
cout << "Enter the number of rows: ";
cin >> m;
cout << "Enter the number of columns: ";
cin >> n;
int values[m][n];
cout << "Enter array values: ";
for (int i = 0; i < m; ++i){
for (int j = 0; j < n; ++j){
cin >> values[i][j];
}
}

int highest, lowest;
highest = values [0][0];
lowest = values [0][0];
for (int i = 0; i < m; ++i){
for (int j = 0; j < n; ++j){
if (highest < values[i][j]) highest = values[i][j];
if (lowest > values[i][j]) lowest = values[i][j];
}
}
cout << "Highest value is: " << highest << endl;
cout << "Lowest value is: " << lowest << endl;
char x;
cout << "Try again? y for YES, n for NO: ";
cin >> x;
switch (x){
case 'y': goto loop;
default: break;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS