using namespace std; void main() { setlocale(LC_ALL, "ukr"); srand(time(NULL)); const int n = 15; int arr[n], m = 0,p = 0; for (int i = 0; i < n; i++) { arr[i] = rand() % 10 - 5; cout << arr[i] << " "; } cout << endl; for (int i = 0; i < n; i++) { if ((arr[i] >= 0) && (arr[i] == 0)) m++; // else // if (p < m) { // p = m; // m = 0; // } } if (p > m) cout << endl << p << endl; else cout << endl << m << endl; } 
  • 2
    When, in your opinion, is the condition in if ((arr[i] > 0) && (arr[i] == 0)) true? - andy.37
  • @ andy.37> = should be - tkachuk
  • @ andy.37 but it just counts 0, not groups - tkachuk
  • Tip: choose more meaningful names for variables than m or p . Honest, it’s easier to write from scratch than to figure it out. - andy.37
  • 2
    You labs to the whole course doing here? ru.stackoverflow.com/q/549903/10105 - VladD

1 answer 1

 void main() { setlocale(LC_ALL, "ukr"); srand(time(NULL)); const int n = 15; int arr[n], m = 0,p = 0; for (int i = 0; i < n; i++) { arr[i] = rand() % 10 - 5; cout << arr[i] << " "; } cout << endl; for (int i = 0; i < n; i++) { if (!arr[i]) m|=1; if ( arr[i] < 0){ p+=m; m = 0; } } cout << endl << p+m << endl; }