동적행렬 할당해서 n차행렬 사칙연산 하는 프로그램 만들려고 하는데
pmat1 , pmat2에 값넣는 부분에서 pmat2 값이 안너어져 이거 뭐가 잘못된거야??
#include <iostream>
using namespace std;
int main(){
int n,m;
cout << "정방 행렬의 크기를 입력하세요 [n][m] ";
cout << "n : "; cin >> n;
cout << "m : "; cin >> m;
int** pmat1 = new int* [n];
int** pmat2 = new int* [n];
for(int i=0; i<n; i++){
pmat1[n] = new int [m];
}
for(int i=0; i<n; i++){
pmat2[n] = new int [m];
}
cout << " 행렬1 ";
for(int i =0; i<n; i++){
for(int j=0; j<m; j++){
pmat1[i][j] = 3;
cout << pmat1[i][j] << " ";
}
cout << "\n";
}
cout << " 행렬2 ";
for(int i =0; i<n; i++){
for(int j=0; j<m; j++){
pmat2[i][j] = 1;
cout << pmat2[i][j] << " ";
}
cout << "\n";
}
}
pmata[n] = new int [m]; 줄 pmata가 아니라 pmat2 같은데...
계속 뜯어고치다가 질문올리는거라 실수함 ㅠㅠ 수정했는데 뭐가잘못된건지 좀 봐주세영
이제 보니 문제가 한 둘이 아니구만. pmat1[n] = new int[m]; pmat2[n] = new int[m]; 에서 [n]이 아니라 [i]지.
와우~ pmat1은 돌아가고 pmat2는 안돌아가서 뭐 다른데서 잘못된건줄 ㅜㅜ 감사합니다