Uses crt; var a,b:array[1..100] of integer; i,j,k,n:integer; procedure rmassr; begin for i:=1 to n do begin a[i]:=random(10); end; end; procedure rmassy; begin for i:=1 to n do begin readln(a[i]); end; end; procedure rmass(); begin for i:=1 to n do begin write(a[i],' '); end; end; procedure newmass; begin for i:=1 to n do begin if a[i] > 0 then b[i]:=a[i]; end; for i:=1 to n do begin j:=j+b[i]; end; writeln('summa = ',j); end; begin clrscr; randomize; write('длина массива '); readln(n); write('1-random; 2-в ручную'); readln(k); if k = 1 then rmassr() else rmassy(); rmass(); writeln(); newmass(); readln end.
var a,b:array[1..100] of integer; i,j,k,n:integer;
procedure rmassr;
begin
for i:=1 to n do begin
a[i]:=random(10);
end;
end;
procedure rmassy;
begin
for i:=1 to n do begin
readln(a[i]);
end;
end;
procedure rmass();
begin
for i:=1 to n do begin
write(a[i],' ');
end;
end;
procedure newmass;
begin
for i:=1 to n do begin
if a[i] > 0 then b[i]:=a[i];
end;
for i:=1 to n do begin
j:=j+b[i];
end;
writeln('summa = ',j);
end;
begin
clrscr;
randomize;
write('длина массива '); readln(n);
write('1-random; 2-в ручную'); readln(k);
if k = 1 then
rmassr()
else rmassy();
rmass();
writeln();
newmass();
readln
end.
#include <iostream>
using namespace std;
int main() {
setlocale(LC_ALL, "");
int N = 10;
int max = -9999999;
int sum = 0;
int choise = 0;
int arr[N] = {0};
cout << "Введите 10 значений: ";
for(int i = 0; i<N; ++i) {
cin >> arr[i];
}
cout << "Введите действие (1 - +, 2 - макс. значение, 3 - колво отр. значений)";
cin >> choise;
if(choise==1) {
for(int i = 0; i<N; ++i) {
sum+=arr[i];
}
cout << endl << "Сумма: " << sum;
}
if(choise==2) {
for(int i = 0; i<N; ++i) {
if(arr[i]>max) {
max = arr[i];
}
}
cout << endl << "Макс. знач: " << max;
}
if(choise==3) {
for(int i = 0; i<N; ++i) {
if(arr[i]<0) {
++sum;
}
}
cout << "Колво отр. знач: " << sum;
}
if(choise!=1&&choise!=2&&choise!=3) {
cout << "Введите корректное значение.";
}
return 0;
}