题目
代码
#include <iostream>
using namespace std;
class Matrix
{
public:
Matrix(int n = 4, int x = 0, int row = 0, int col = 0);
void input(int a[][4]);
void find();
void print();
private:
int p[4][4];
int n;
int x;
int row, col;
};
Matrix::Matrix(int n, int x, int row, int col)
{
this->n = n;
this->x = x;
this->row = row;
this->col = col;
}
void Matrix::input(int a[][4])
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
p[i][j] = a[i][j];
}
}
}
void Matrix::find()
{
int min_index1 = 0, min_index2 = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (p[i][j] < p[min_index1][min_index2])
{
min_index1 = i;
min_index2 = j;
}
}
}
x = p[min_index1][min_index2];
row = min_index1 + 1;
col = min_index2 + 1;
}
void Matrix::print()
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
cout << p[i][j] << " ";
}
cout << endl;
}
cout << "x= " << x << endl;
cout << "row = " << row << endl;
cout << "col = " << col << endl;
}
int main()
{
int a[][4] = { 17,2,3,4,5,6,7,8,9,10,1,12,13,14,15,16 };
Matrix m;
m.input(a);
m.find();
m.print();
return 0;
}