Есть ответ 👍

Дан массив целых чисел. все элементы,оканчивающиеся цифрой 4,уменьшить вдвое на с++

117
284
Посмотреть ответы 2

Ответы на вопрос:


#include < cstdlib> #include < iostream> using namespace std; int main(int argc, char *argv[]){      int n;       cout< < "введите количество элементов массива."< < endl;       cin> > n;       int mas1[n];       int mas2[n];             for(int i=0; i< n; i++){      mas1[i] = rand()%100; //заполняем массив случайными числами от 0 до 100      if(mas1[i]%10 == 4) {                                mas2[i]=mas1[i]/2;                                 cout< < "замена! ";                                 }      else {cout< < "\t";                 mas2[i]=mas1[i];                 }      cout< < mas1[i]< < '\t'< < mas2[i]< < endl;       }      system("pause");       return exit_success; }

MarrySen
4,5(33 оценок)

program delin;

const

  nn = 100; // максимальный размер массива

var

  i, j, n, t: integer;

  a: array[1..nn] of integer;

begin

  write('n = ');

  read(n);

  randomize;

  for i : = 1 to n do

  begin

    a[i] : = random(38) - 9;

    write(a[i], ' ');

  end;

  writeln;

  for i : = n - 1 downto 1 do

    for j : = 1 to i do

      if a[j] > a[j + 1] then

      begin

        t : = a[j];

        a[j] : = a[j + 1];

        a[j + 1] : = t;

      end;

  for i : = 1 to n do

    write(a[i], ' ');

end.

Популярно: Информатика