Дан массив целых чисел. все элементы,оканчивающиеся цифрой 4,уменьшить вдвое на с++
Ответы на вопрос:
#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; }
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.
Популярно: Информатика
-
ОМЛА06.08.2021 07:00
-
Kuznecovanaste28.01.2021 14:04
-
zhenyakulakova26.01.2021 17:39
-
helsey20.05.2021 16:16
-
миккимаус189067716.11.2021 19:13
-
лох24825.07.2020 19:26
-
ilmir12345678927.06.2022 18:03
-
няшка36621.05.2023 14:12
-
dima102507.12.2021 01:33
-
GlaydoN20.04.2020 22:25