//C++로 시작하는 객체지향 프로그래밍 p.361 예제 8.17 - 가장 큰 요소의 위치
#include <iostream>
using namespace std;
const int ROW_SIZE = 3;
const int COLUMN_SIZE = 4;
void locateLargest(const double a[][4], int location[]) {
int row = 0, column = 0;
double maxvalue = a[0][0];
for (int i = 0; i < ROW_SIZE; i++) {
for(int j = 0; j < COLUMN_SIZE; j++)
if (maxvalue < a[i][j]) {
row = i;
column = j;
maxvalue = a[i][j];
}
}
location[0] = row;
location[1] = column;
}
int main() {
double array[3][4];
cout << "Enter the array: ";
for (int i = 0; i < ROW_SIZE; i++) {
for (int j = 0; j < COLUMN_SIZE; j++) {
cin >> array[i][j];
}
}
int loc[2];
locateLargest(array, loc);
cout << "The location of the largest element is " <<
array[loc[0]][loc[1]] << "at (" << loc[0] << ", " << loc[1] << ")" << endl;
system("pause");
return 0;
}
댓글 없음:
댓글 쓰기