kilolilo

matrix 1.1 not work. n/2

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