{ int massiv[1000],i; int sum ; double pr1=1, randomize(); for (int i = 0; i < 1000; i++) //Заполнение массива { massiv[i] = -5 + rand() % 56; printf (" %d;", massiv[i]);} //Выводятся все элементы массива for (int i =1000-1; i>0; i--) { if (massiv[i]>=0) { pr1=massiv[i]*pr1; sum *= massiv[i]; } else break; } while (massiv[i]!=0); printf ("Result: %.0lf ", pr1); getchar(); getchar(); return 0; 

Where is the while statement, I can't write the body of the loop correctly. I write the sum, displays the wrong data (I work in Turbo C ++).

    1 answer 1

     int sum = 0; for (int i = 999; (i >=0) && (massiv[i] >=0); sum += massiv[i--]); printf ("Result: %d\n", sum); 
    • array gives, and the amount of e-s is not. I, apparently, also in the error code :( Problem condition:. Given a one-dimensional array of 1000 elements, consisting of random integers in the range from -5 to 50. Find the sum of the elements of the array, from the end of the array, to the first negative element. - smthelse
    • 1. Fill the array. You do it like the right thing. Next, throw your code. 2. Consider the required amount as I wrote. 3. Pass the code to the teacher. - skegg
    • Pass the code to the teacher. And get a pair and outfit out of turn. On the first negative element, the sum calculation will stop. - BuilderC
    • one
      See the conditions of the problem. - skegg
    • @smthelse, specify, before the first negative element - the first from the beginning or the first from the end? - skegg