Cum as putea extrage o submatrice dintr-o matrice ?, capetele acesteia(submatricei) fiind introduse de la tastatura?
Răspunsuri la întrebare
#include <iostream>
using namespace std;
int a[100][100]; // Matrice mare
int b[100][100]; // Matrice mica
int main(){
//Citire matrice
int n,m,i,j;
cout << "Introduceti dimensiuni : ";
cin >> n >> m;
cout << "Introduceti matrice : \n";
for(i=1;i<=n;i++){
for(j=1;j<=m;j++) cin >> a[i][j];
}
//Citire coordonate capete
int pi,pj,qi,qj;
cout << "Introduceti coordonate cap I : ";
cin >> pi >> pj;
cout << "Introduceti coordonate cap II : ";
cin >> qi >> qj;
//Construire submatrice
for(i=pi;i<=qi;i++){
for(j=pj;j<=qj;j++) b[i-pi+1][j-pj+1] = a[i][j];
}
//Afisare matrice mica
cout << "Submatrice :\n";
for(i=1;i<qi-pi+2;i++){
for(j=1;j<qj-pj+2;j++) cout << b[i][j]<< " ";
cout << endl;
}
}