Guest User

Untitled

a guest
May 21st, 2018
109
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. using namespace std;
  3.  
  4. void sort (int **&mas,int n)
  5. {
  6.     int x;
  7.     for( int i=0; i < n; i++)
  8.     {          
  9.         for( int j = n-1; j > i; j-- )
  10.         {    
  11.             if ( mas[j-1][j-1] > mas[j][j] )
  12.             {
  13.             x=mas[j-1][j-1];
  14.             mas[j-1][j-1]=mas[j][j];
  15.             mas[j][j]=x;
  16.             }
  17.         }
  18.     }
  19. }
  20. int sum (int **mas,int n)
  21. {
  22.     int sum=0;
  23.     for(int i=0; i<n; i++)
  24.     {
  25.         for(int j=0; j<n; j++)
  26.         {
  27.             sum+=mas[i][j];
  28.         }
  29.     }
  30.     return sum;
  31. }
  32. void show(int **mas,int n)
  33. {
  34.     for(int i=0; i<n; i++)
  35.     {
  36.         for(int j=0; j<n; j++)
  37.         {
  38.             cout<<mas[i][j]<<"\t";
  39.         }
  40.     cout<<endl;
  41.     }
  42. }
  43. void main()
  44. {
  45.     const int n=5;
  46.     int **mas;
  47.     mas = new int*[n];
  48.     int i;
  49.     for(i=0; i<n; i++)
  50.     {
  51.         mas[i]=new int [n];
  52.     }
  53.     for(i=0; i<n; i++)
  54.     {
  55.         for(int j=0; j<n; j++)
  56.         {
  57.             mas[i][j]=rand()%100-50;
  58.         }
  59.     }
  60.     show(mas,n);
  61.     cout<<endl<<"Summa: "<<sum(mas,n)<<endl;
  62.     sort(mas,n);
  63.     cout<<endl;
  64.     show(mas,n);
  65. }
Add Comment
Please, Sign In to add comment