Program Pascal1; uses Crt; const m=4; n=2; var a:array[1..m,1..n] of real; i,j,k:integer; begin ClrScr; Randomize; Writeln('Сформированный масcив'); k:=0; for i:=1 to m do begin for j:=1 to n do begin a[i,j]:=Random(31)-15.0; Write(a[i,j]:6:1); if a[i,j]=10 then Inc(k) end; Writeln end; Writeln('Количество элементов, равных 10: ',k); Write('Нулевые элементы: '); for i:=1 to m do for j:=1 to n do if a[i,j]=0 then Write('a[',i,',',j,'] '); Writeln end.
1)
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
signed main() {
srand(time(NULL));
int n;
cin >> n;
int a[n];
for(int i = 0; i < n; i++)
a[i] = rand() % 5 + 1;
vector<int> ans;
for(int i = 0; i < n; i++)
{
cout << a[i] << " ";
if(a[i] == a[0])
ans.push_back(i);
}
cout << "\n";
for(auto i: ans)
cout << i << " ";
}
2)
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
signed main() {
int n,k;
cin >> n >> k;
int a[n];
vector<int> ans;
for(int i = 0; i < n; i++)
{
cin >> a[i];
if(a[i] % k == 0)
ans.push_back(a[i]);
}
for(auto i: ans)
cout << i << " ";
}
3)
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
signed main() {
int n,z;
cin >> n >> z;
int a[n];
for(int i = 0; i < n; i++)
{
cin >> a[i];
a[i] = min(a[i],z);
}
for(auto i: a)
cout << i << " ";
}
uses Crt;
const
m=4;
n=2;
var
a:array[1..m,1..n] of real;
i,j,k:integer;
begin
ClrScr;
Randomize;
Writeln('Сформированный масcив');
k:=0;
for i:=1 to m do begin
for j:=1 to n do begin
a[i,j]:=Random(31)-15.0;
Write(a[i,j]:6:1);
if a[i,j]=10 then Inc(k)
end;
Writeln
end;
Writeln('Количество элементов, равных 10: ',k);
Write('Нулевые элементы: ');
for i:=1 to m do
for j:=1 to n do
if a[i,j]=0 then Write('a[',i,',',j,'] ');
Writeln
end.
Вариант выполнения: