View Code of Problem 45

#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n][n];
	for(int i=0;i<n;i++)
	  for(int j=0;j<n;j++)
	    cin>>a[i][j];
		
	for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
		{
			int temp;
			temp=a[i][j];
			a[i][j]=a[j][i];
			a[j][i]=temp;
		}
		
	for(int i=0;i<n;i++)
	  for(int j=0;j<n;j++)
	    {
		  cout<<a[i][j]; 
		  if(i<n-1||j<n-1) cout<<" ";
		  if(j==n-1&&i<n-1) cout<<endl;
		}
}

Double click to view unformatted code.


Back to problem 45