Advertisement
High_Light

transposition

Nov 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void uber(int **a,int n){
  5.     int ch=0;
  6.     for(int i=0;i<n;i++){
  7.         for(int j=0;j<n;j++){
  8.             ch+=1;
  9.             a[i][j]=ch;
  10.         }
  11.     }
  12. }
  13.  
  14. void print(int **a,int n){
  15.     for(int i=0;i<n;i++){
  16.         for(int j=0;j<n;j++){
  17.             cout<<a[i][j]<<"\t";
  18.         }
  19.         cout<<endl<<endl;
  20.     }
  21. }
  22.  
  23. void transpose(int **a, int n){
  24.     int c;
  25.     for(int i=0;i<n;i++){
  26.         for(int j=0;j<n;j++){
  27.             if (j > i){
  28.                 c=a[j][i];
  29.                 a[j][i] = a[i][j];
  30.                 a[i][j] = c;
  31.             }
  32.         }
  33.     }
  34. }
  35.  
  36. int main()
  37. {
  38.     int b=5;
  39.     int **ptr = new int *[b];
  40.     for ( int i=0; i<b; i++){
  41.        ptr[i] = new int [b];
  42.        for(int j=0;j<b;j++){
  43.            ptr[i][j]=0;
  44.            }
  45.     }
  46.     uber (ptr,b);
  47.     print (ptr,b);
  48.     cout << endl;
  49.     transpose(ptr, b);
  50.     print (ptr,b);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement