#include <iostream>
#include <ctime>
using namespace std;
void inp(int** x,int n);
void out(int** x,int n);
void replace(int** x,int n);
int main()
{
int n;
cout<<"n=";
cin>>n;
int** x=new int*[n];
for(int i=0;i<n;i++)
x[i]=new int[n];
inp(x,n);
out(x,n);
replace(x,n);
cout<<endl<<endl;
out(x,n);
for(int i=0;i<n;i++)
delete[] x[i];
delete[] x;
return 0;
}
void inp(int** x,int n)
{
srand(time(0));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
*(*(x+i)+j)=rand()%10;
}
void out(int** x,int n)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
cout<<*(*(x+i)+j)<<" ";
cout<<endl;
}
}
void replace(int** x,int n)
{
int buff;
for(int i=0;i<n;i++)
for(int j=0;j<i;j++)
{
buff=*(*(x+i)+j);
*(*(x+i)+j)=*(*(x+j)+i);
*(*(x+j)+i)=buff;
}
}
|