Advertisement
Xsufu

Untitled

Feb 12th, 2020
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. #include <iostream> //ââîä è âûâîä
  2. #include <string.h>     //ñòðèíãîâûé òèï
  3. #include <windows.h> //system äëÿ íåêîòîðûõ êîìïèëÿòîðîâ
  4. #include <time.h>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. void start();
  9. void genMass(int*, int);
  10. void printMass(int*, int);
  11. void maxMass(int*, int, int);
  12. void sortMass(int*, int);
  13.  
  14. int main(){
  15.     setlocale(LC_ALL,"RUSSIAN");
  16.  
  17.     start();
  18.    
  19.     system("pause");
  20.     return 0;
  21. }
  22.  
  23. void start(){
  24.     int n;
  25.     srand(time(NULL));
  26.  
  27.     n = 1+rand()%10;
  28.     int *arr1 = new int[n];
  29.     genMass( arr1, n);
  30.     printMass( arr1, n);
  31.     int n1 = n;
  32.  
  33.     n = 1+rand()%10;
  34.     int *arr2 = new int[n];
  35.     genMass( arr2, n);
  36.     printMass( arr2, n);
  37.     int n2 = n;
  38.    
  39.     n = 1+rand()%10;
  40.     int *arr3 = new int[n];
  41.     genMass( arr3, n);
  42.     printMass( arr3, n);
  43.     int n3 = n;
  44.    
  45.     n = 1+rand()%10;
  46.     int *arr4 = new int[n];
  47.     genMass( arr4, n);
  48.     printMass( arr4, n);
  49.     int n4 = n;
  50.    
  51.     n = 1+rand()%10;
  52.     int *arr5 = new int[n];
  53.     genMass( arr5, n);
  54.     printMass( arr5, n);
  55.     int n5 = n;
  56.    
  57.     cout << endl;
  58.     maxMass (arr1, n1, 1);
  59.     maxMass (arr2, n2, 2);
  60.     maxMass (arr3, n3, 3);
  61.     maxMass (arr4, n4, 4);
  62.     maxMass (arr5, n5, 5);
  63.     cout << endl;
  64.     sortMass (arr1, n1);
  65.     printMass (arr1, n1);
  66.     sortMass (arr2, n2);
  67.     printMass (arr2, n2);
  68.     sortMass (arr3, n3);
  69.     printMass (arr3, n3);
  70.     sortMass (arr4, n4);
  71.     printMass (arr4, n4);
  72.     sortMass (arr5, n5);
  73.     printMass (arr5, n5);
  74. }
  75.  
  76. void genMass(int *arr, int n){
  77.     int num;
  78.     for ( int i = 0; i<n; i++ ){
  79.         num = 1+rand()%100;
  80.         arr[i] = num;
  81.     }
  82. }
  83.  
  84. void printMass(int *arr, int n) {
  85.     for ( int i = 0; i<n; i++ )
  86.         cout << arr[i] << " ";
  87.     cout << endl;
  88. }
  89.  
  90. void maxMass(int *arr, int n, int p){
  91.     int max = 0;
  92.     for (int i = 0; i<n; i++){
  93.         if ( arr[i] > max )
  94.             max = arr[i];
  95.            
  96.     }
  97.     cout << "Ìàêñèìàëüíîå ÷èñëî " << p << "-ãî ìàññèâà ðàâíî " << max << endl;
  98. }
  99.  
  100. void sortMass (int *arr, int n){
  101.     int change = 0;
  102.     for (int d = 0; d < n; d++){
  103.         for ( int i = 0; i<n-1; i++ ){
  104.             if ( arr[i] > arr[i+1] ){
  105.                 change = arr[i+1];
  106.                 arr [i+1] = arr[i];
  107.                 arr [i] = change;
  108.             }
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement