• Дан массив А ( 28 ) . Найти сумму положитель " ых элементов массива . Если сумма будет больше 100 , то обнулить элементы в чётных ячейках , ссли сумма будет меньше или равна 100 , то обнулить элементы в нечетных ячейках

Ответы 2

  • #include <iostream>#include <stdlib.h>#include <time.h>using namespace std;const int n = 28;int main(){    int A[n];    int sum = 0;    cout << "Source array: ";    srand(time(NULL));    for (int i = 0; i < n; i++) {            A[i] = rand() % 23 - 10;            if (A[i] > 0) sum += A[i];            cout << A[i] << " ";    }    cout << "Sum = " << sum << endl;    cout << "New array: ";    if (sum > 100)    for (int i = 0; i < n; i++)    {        if (i % 2 == 1) A[i] = 0;        cout << A[i] << " ";    }    else    for (int i = 0; i < n; i++)    {        if (i % 2 == 0) A[i] = 0;        cout << A[i] << " ";    }    cout << endl;    system("pause");    return 0;}
    • Автор:

      carly
    • 6 лет назад
    • 0
  • const  n=28;var  a:array[1..n] of integer;  i:byte;  s:integer;begin  randomize;  for i:=1 to n do    begin    a[i]:=random(41)-20;    Write(a[i],' ');    if a[i]>0 then s:=s+a[i]    end;  writeln;  if s>100 then    begin    i:=2;    while i<=n do      begin      a[i]:=0;      i:=i+2      end    end  else    begin    i:=1;    while i<=n do      begin      a[i]:=0;      i:=i+2      end    end;  writeln('Сумма равна ',s);  for i:=1 to n do Write(a[i],' ');  writelnend.
    • Автор:

      contreras
    • 6 лет назад
    • 0
  • Добавить свой ответ

Еще вопросы

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years