#include
using namespace std;
void Input(int *a, int rows) {
for (int i=0;i cout << "Input row [" << i << "]:";
for (int j=0;j<6;j++) {
cin >> *(a + i*6 +j);
}
}
}
double Average(int *a, int size) {
double sum = 0.0;
for (int i=0;i sum += *(a+i);
return sum/size;
}
/**
* 返回最大值所在行、列号
*/
void Max(int *a, int rows, int cols, int *r, int *c) {
int *b = a+1, m = *a;
*r = 0; *c = 0;
while (b!=a+rows*cols) {
if (*b>m) {
m = *b;
*r = (b-a)/cols;
*c = (b-a)%cols;
}
b++;
}
}
//冒泡排序
void Sort(int *a, int size) {
int t;
for (int i=0;i for (int j=0;j if (*(a+j) >*(a+j+1)) {
t = *(a+j);
*(a+j) = *(a+j+1);
*(a+j+1) = t;
}
}
}
}
void Display(int *a, int rows, int cols) {
cout << "--------------------------" << endl;
for (int i=0;i for (int j=0;j cout << *(a+i*rows+j) << " ";
}
cout << endl;
}
cout << "--------------------------" << endl;
}
int main() {
int a[6][6], row, col;
Input((int*)a, 6);
Display((int*)a, 6, 6);
cout << "平均值:" << Average((int*)a, 6*6) << endl;
Max((int*)a, 6, 6, &row, &col);
cout << "最大值:" << a[row][col] << ", 所在行:" << row << ",列:" << col << endl;
Sort((int*)a, 6*6);
Display((int*)a, 6, 6);
return 0;
}