#include<iostream>
using namespace std;
void Print(int*M, int row, int col)
{
for (int i = 0;i < row;i++)
{
for (int j = 0;j < col;j++)
{
cout << *((M + i*col) + j) << "\t";
}
cout << endl;
}
}
int**Max(int*M, int row, int col)
{
int**data = (int**)malloc(sizeof(int*)*row);
for (int i = 0;i < row;i++)
data[i] = (int*)malloc(sizeof(int)*col);
for (int i = 0;i < row;i++)
{
int max = *(M + i * col);
for (int j = 0;j < col;j++)
{
if (max < *(M + i * col + j))
{
max = *(M + i * col + j);
data[i][0] = max;
data[i][1] = j;
}
}
}
return data;
}
int main()
{
int a[2][3] = { 1,2,3,4,5,6 };
Print((int*)a,2,3);
int**data = Max((int*)a, 2, 3);
for(int i=0;i<2;i++)
for (int j = 0;j < 2;j++)
{
cout << data[i][j] << " ";
}
system("pause");
}
C++返回二维数组
最新推荐文章于 2020-12-06 03:27:58 发布