fork(2) download
  1. #include <iostream>
  2. #include <clocale>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. setlocale(LC_ALL, "ru");
  9. srand(time(NULL));
  10.  
  11. const int LENGTH = 10;
  12. int array[LENGTH];
  13.  
  14. const int LENGTH2 = LENGTH - 2;
  15. int array2[LENGTH2];
  16.  
  17. for (int i = 0; i < LENGTH; i++)
  18. {
  19. array[i] = rand() % 19;
  20. cout << array[i] << " ";
  21. }
  22. cout << endl;
  23.  
  24. int idx_maxV = 0;
  25. for (int i = 1; i < LENGTH; ++i)
  26. {
  27. if (array[i] > array[idx_maxV])
  28. idx_maxV = i;
  29. }
  30.  
  31. int idx_minV = 0;
  32. for (int i = 1; i < LENGTH; ++i)
  33. {
  34. if (array[i] < array[idx_minV])
  35. idx_minV = i;
  36. }
  37.  
  38. cout << "maxV = " << array[idx_maxV] << "\nminV = " << array[idx_minV] << endl;
  39.  
  40. for (int i = 0, j = 0; i < LENGTH; ++i)
  41. {
  42. if (i == idx_maxV)
  43. idx_maxV = -1;
  44. else if (i == idx_minV)
  45. idx_minV = -1;
  46. else
  47. array2[j++] = array[i];
  48. }
  49.  
  50. for (int i = 0; i < LENGTH2; i++)
  51. {
  52. cout << array2[i] << " ";
  53. }
  54. cout << endl;
  55. }
Success #stdin #stdout 0.01s 5472KB
stdin
Standard input is empty
stdout
6  18  0  11  10  5  8  4  13  7  
maxV = 18
minV = 0
6  11  10  5  8  4  13  7