Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "Rus");
- const int n = 10; // размерность массива
- int A[n], i;
- int s1 = 0; // положительные числа
- int s2 = 0; // отрицательные числа
- for (i = 0; i < n; i++) {
- A[i] = rand()%100 - 50;
- cout << A[i]<<" ";
- }
- cout << endl;
- int max = 0;
- for (i = 0; i < n; i++) {
- if (A[i] > max) {
- max = A[i];
- }
- }
- cout << max << endl;
- int q;
- for (i = 0; i < n; i++) {
- if (max == A[i]) {
- q = i;
- break;
- }
- }
- for (i = q+1; i < n; i++) {
- if (A[i] > 0) {
- s1 += A[i];
- }
- }
- for (i = 0; i < q; i++) {
- if (A[i] < 0) {
- s2 += A[i];
- }
- }
- cout << s1 << ' ' << s2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement