AndreyKlipikov

[Niyaz] Prog. Tikket N10. 2

Dec 30th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     srand(time(NULL));
  9.  
  10.  
  11.     const int n = 7;
  12.     double a[n], average = 0;
  13.     for (int i = 0; i < n; i++) {
  14.             a[i] = rand() % 10 - 2;
  15.             cout << a[i] << " ";
  16.             average += a[i];
  17.     }
  18.     average /= n;
  19.     cout << endl << endl << average << endl;
  20.  
  21.  
  22.     bool next = a[1] < average;
  23.     int deleted = 0;
  24.     for (int i = 0; i < n - deleted; i++) {
  25.         if ((next && a[i] < average) || (!next && a[i] < average && a[i + 1] < average)) {
  26.             for(int j = i; j < n - 1; j++)
  27.                 a[j] = a[j + 1];
  28.             deleted++;
  29.             --i;
  30.         }
  31.         next = a[i + 1] < average;
  32.     }
  33.     cout << endl;
  34.  
  35.  
  36.     for (int i = 0; i < n - deleted; i++)
  37.         cout << a[i] << " ";
  38.     cout << endl;
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment