fork download
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7.  
  8. void aMin(int arr[], int n)
  9. {
  10. int j = 0;
  11. for (int i = 0; i < n; i++)
  12. {
  13. if (arr[i] >= 1)
  14. {
  15. swap(arr[i], arr[j]);
  16. j++;
  17. }
  18. }
  19. }
  20.  
  21. int gMin(int arr[], int n)
  22. {
  23. return *min_element(arr, arr + n);
  24. }
  25.  
  26. int makeR(int z)
  27. {
  28. int j = rand() % 6 + (-2);
  29. return j;
  30. }
  31. int main()
  32. {
  33. int ni1 = -1; int ni2 = -1;
  34. srand(time(0));
  35. int C[6];
  36. for(int i = 0; i < 6; i++)
  37. {
  38. C[i] = makeR(i);
  39. cout << C[i] << " ";
  40. }
  41. putchar('\n');
  42. cout << "Minimum element of array: " << gMin(C, 6) << " " << "\n";
  43. int sum = 0;
  44. for (int i = 0; i < 6; i++)
  45. {
  46. if (C[i] < 0)
  47. {
  48. if ( ni1 == -1)
  49. {
  50. ni1 = i;
  51. }
  52. else
  53. {
  54. ni2 = i;
  55. break;
  56. }
  57. }
  58. }
  59. if ( ni1 != -1 && ni2 != -1)
  60. {
  61. for (int i = ni1 + 1; i < ni2; i++)
  62. {
  63. sum += C[i];
  64. }
  65. }
  66.  
  67. cout << "Sum of negative Btwn 2 indexes is: " << sum << endl;
  68. aMin(C, 6);
  69. cout << "Our array sorted : ";
  70. for (int i = 0; i < 6; i++)
  71. {
  72. cout << C[i] << " ";
  73. }
  74. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
0 1 2 -1 0 -2 
Minimum element of array: -2 
Sum of negative Btwn 2 indexes is: 0
Our array sorted : 1 2 0 -1 0 -2