#include <iostream> #include <conio.h> #include <time.h> using namespace std;
void main() { srand(time(NULL)); setlocale(0, ""); int arr[17]; int a, b, chet=0, nechet = 0; cout << "Введите диапазон ." << endl << "Нижняя граница диапазона: "; cin >> a; cout << "Верхняя граница диапазона: "; cin >> b; cout << endl; for (int i = 0; i < 17; ++i) { arr[i] = a + rand() % (b-a+1); cout <<" "<<arr[i]; } for (int i = 0; i < 17; ++i) { if (arr[i] % 2 == 0) chet++; else nechet++; } if (chet > nechet) cout << " \n Четных больше"; else if (nechet>chet) cout << "\n Нечетных больше"; else cout << "\n Одинаковое количество четных и нечетных"; _getch(); }
Anastasiya1537
09.08.2022
// PascalABC.Net 3.0, версия 1066 const mm=50; nn=50; var n,m,i,j,k1,k2,p:integer; s1,s2,s3:longint; a:array[1..mm,1..nn] of integer; begin Write('Число строк и столбцов массива: '); Read(m,n); Write('Значение p: '); Read(p); Writeln('*** Сгенерированный массив ***'); Randomize; s1:=0; s2:=0; s3:=0; k1:=0; k2:=0; for i:=1 to m do begin for j:=1 to n do begin a[i,j]:=Random(101)-50; Write(a[i,j]:4); if a[i,j]>30 then s1:=s1+a[i,j]; if Odd(a[i,j]) then Inc(k1) else begin s2:=s2+a[i,j]; Inc(k2) end; if i+j=p then s3:=s3+a[i,j] end; Writeln end; Writeln('Сумма элементов массива, больших 30: ',s1); Writeln('Количество нечетных элементов массива: ',k1); Writeln('Среднее арифметическое четных элементов массива: ',s2/k2); Writeln('Сумма элементов массива c суммой индексов ',p,': ',s3) end.
var
a, b, x, s, p: integer;
begin
writeln(' Ввести х');
readln(x);
s := 0;
x := Abs(x); { защита от ввода отрицательных }
while x > 0 do
begin
s := s + x mod 10;
x := x div 10
end;
writeln(' Сумма цифр=', s);
end.