#include<bits/stdc++.h>
#include
using namespace std;
void reverse(int a[][1000],int n){
//reverse each row
for(int row=0;row<n;row++){
int start_col=0;
int end_col=n-1;
while(start_col<end_col){
swap(a[row][start_col],a[row][end_col]);
start_col++;
end_col–;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i<j){
swap(a[i][j],a[j][i]);
}
}
}
}
void display(int a[][1000],int n){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
int main(){
int n;
cin>>n;
int a[1000][1000];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
static int k=1;
a[i][j]=k;
k++;
}
}
reverse(a,n);
display(a,n);
}
Code is not working
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.