动态申请二维数组
int main() {
int **p;
int m,n;
cout << "请输入行数和列数:" << endl;
cin >> m >> n;
p = new int *[m];
for(int i = 0;i <= m-1;i++){
p[i]=new int[n];
}
for(int row = 0;row <= m-1;row++){
for(int col = 0; col <= n-1;col++){
p[row][col] = 0;
}
}
int **p;
int m,n;
cout << "请输入行数和列数:" << endl;
cin >> m >> n;
p = new int *[m];
for(int i = 0;i <= m-1;i++){
p[i]=new int[n];
}
for(int row = 0;row <= m-1;row++){
for(int col = 0; col <= n-1;col++){
p[row][col] = 0;
}
}
for(row = 0;row <= m-1;row++){
for(int col = 0; col <= n-1;col++){
cout << p[row][col] << "\t";
}
cout << "\n";
}
for(int col = 0; col <= n-1;col++){
cout << p[row][col] << "\t";
}
cout << "\n";
}
for(row = 0;row <= m-1;row++){
delete [] p[row];
}
delete []p;
delete [] p[row];
}
delete []p;
system("pause");
return 0;
}
return 0;
}