Va rog ajutati-ma aveti in poza exercițiul
Răspunsuri la întrebare
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("mat.in");
ofstream fout("mat.out");
void schimba(float *a, float *b, int n){
for(int i = 1; i<=n;i++){
float x = a[i];
a[i] = b[i];
b[i] = x;
}
}
float m[10000][10000];
int main(){
int n;
fin >> n;
for(int i = 1;i <= n; i++){
for(int j = 1; j <= n; j++)
fin >> m[i][j];
}
fin.close();
int l1,l2;
cin >> l1 >> l2;
schimba(m[l1], m[l2], n);
for(int i = 1;i <= n; i++){
for(int j = 1; j <= n; j++)
fout << m[i][j]<<' ';
fout << '\n';
}
fout.close();
return 0;
}
Raspuns:
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("mat.in");
int n,i,j,l1,l2;
float a [100][100],aux;
int main ()
{
f>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
f>>a[i][j];
cout<<"l1=";
cin>>l1;
cout<<"l2=";
cin>>l2;
for(i=1;i<=n;i++)
{
aux=a[l1][i];
a[l1][i]=a[l2][i];
a[l2][i]=aux;
}
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
return 0;
}
Explicație pas cu pas: