As dorii rezolvarea problemelor de mai jos va rog frumos ( matrici)
Răspunsuri la întrebare
Problema 35
#include <iostream>
using namespace std;
int main()
{
int m,n,x,y;
cout<<"Dati dimensiunea matricii m si n:";
cout<<"\nm=";cin>>m;
cout<<"n=";cin>>n;
int a[m][n];
for(int i=1; i<=m; i++){
for(int j=1; j<=n; j++){
cout<<"A["<<i<<"]["<<j<<"]="; cin>>a[i][j];
}
}
cout<<"\nMatricea obtinuta:\n";
for(int i=1; i<=m; i++){
cout<<"\n";
for(int j=1; j<=n; j++){
cout<<" "<<a[i][j];
}
}
cout<<"\nDati x si y:";
cout<<"\nx=";cin>>x;
cout<<"y=";cin>>y;
int aux;
for(int i=x, j=1; j<=n; j++){
aux=a[x][j];
a[x][j]=a[y][j];
a[y][j]=aux;
}
cout<<"\nMatricea obtinuta dupa schimbarea liniilor:\n";
for(int i=1; i<=m; i++){
cout<<"\n";
for(int j=1; j<=n; j++){
cout<<" "<<a[i][j];
}
}
return 0;
}
Problema 21
#include <iostream>
using namespace std;
int main()
{
int m,n;
int max, min;
cout<<"Dati dimensiunea matricii n si m:";
cout<<"\nn=";cin>>m;
cout<<"m=";cin>>n;
int a[n][m];
for(int i=1; i<=m; i++){
for(int j=1; j<=n; j++){
cout<<"A["<<i<<"]["<<j<<"]="; cin>>a[i][j];
}
}
cout<<"\nMatricea obtinuta:\n";
for(int i=1; i<=m; i++){
cout<<"\n";
for(int j=1; j<=n; j++){
cout<<" "<<a[i][j];
}
}
min=0;
max=0;
for(int i=1; i<=m; i++){
for(int j=1; j<=n; j++){
if(a[i][j]>max){
max=a[i][j];
}
if(a[i][j]<min){
min=a[i][j];
}
}
}
for(int i=1; i<=m; i++){
for(int j=1; j<=n; j++){
if(a[i][j]==max){
a[i][j]=min;
j++;
}
if(a[i][j]==min){
a[i][j]=max;
}
}
}
cout<<"\nMatricea obtinuta dupa schimbarea max cu min:\n";
for(int i=1; i<=m; i++){
cout<<"\n";
for(int j=1; j<=n; j++){
cout<<" "<<a[i][j];
}
}
return 0;
}