Advertisement
semsem_elazazy

I. Swapping With Matrix

Feb 19th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. #define ll long long
  4. using namespace std;
  5.  
  6. int swapping_rows(int x , int y, int arr[][],int n){
  7.     for(int i =0 ;i<n ; i++){
  8.      for(int j=0 ; j<n ; j++){
  9.          swap(arr[x][j],arr[y][j]);
  10.      }
  11.        
  12.     }
  13.     return arr ;
  14. }
  15. int swapping_coloumns(int x , int y,int arr[][],int n){
  16.     for(int i =0 ;i<n ; i++){
  17.      for(int j=0 ; j<n ; j++){
  18.          swap(arr[i][x],arr[i][y]);
  19.      }
  20.        
  21.     }
  22.     return arr ;
  23. }
  24.  
  25.  
  26.  
  27. int main() {
  28.    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  29.  
  30.  int n, x,y;
  31.  cin>>n>>x>>y;
  32.  int arr[n][n];
  33.  for(int i =0 ;i<n ; i++){
  34.      for(int j=0 ; j<n ; j++){
  35.         cin>>arr[i][j];
  36.      }
  37.      
  38.  }
  39.  swapping_rows(x,y,arr,n);
  40.  swapping_coloumns(x,y,arr,n);
  41.  for(int i =0 ;i<n ;i++){
  42.      for(int j=0 ;j<n ; j++){
  43.          cout<<arr[i][j];
  44.      }
  45.  }
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement