#include <iostream> #include <ctime> int main() { using namespace std;
const int SIZE = 25; int massive[SIZE];
//1й пункт cout << "Enter number: "; int num; cin >> num; int s = 0; for (int i = 1; i <= num; i++) if (num % i == 0) if (i % 2 == 1) s = s + i; cout << "The sum of the odd divisors: " << s << endl;
//2й пункт for (int i = 0; i < SIZE; i++) { cout << "Enter #" << i + 1 << " element: "; cin >> massive[i]; } for (int i = 0; i < SIZE; i++) if (massive[i] < 0) { massive[i] = 0; break; } for (int i = 0; i < SIZE; i++) cout << massive[i] << ' ';
//3й пункт for (int i = 0; i < SIZE; i++) massive[i] = i + 1; for (int i = 0; i < SIZE; i++) if (massive[i] % 3 == 0) massive[i] *= massive[2]; cout << endl; for (int i = 0; i < SIZE; i++) cout << massive[i] << ' ';
//4й пункт srand(time(0)); for (int i = 0; i < SIZE; i++) massive[i] = rand(); cout << endl; for (int i = 0; i < SIZE; i++) cout << massive[i] << ' '; cout << endl; cout << "Enter number: "; int num2; cin >> num2; bool ifsum = false; for (int i = 0; i < SIZE - 1; i++) if (massive[i] + massive[i + 1] == num2) { ifsum = true; break; } if (ifsum) cout << "yes"; else cout << "no"; cout << endl; return 0; }
Program _9; Type marr = array [1..100,1..100] of real; procedure p1(var x:marr;r1,r2:integer); var i,j:integer; begin for i:=1 to r1 do begin for j:=1 to r2 do begin x[i,j]:=random(10); write(x[i,j]:4); end; writeln; end; end; function f1(var x:marr;r1,r2:integer):integer; var i,j,k:integer; begin k:=0; for i:=1 to r1 do for j:=1 to r2 do if (x[i,j]>=0)and(x[i,j]<=1) then k:=k+1; f1:=k; end; Var a,b: marr; n,m,s,d: integer; Begin randomize; writeln('n,m:'); readln(n,m); writeln('Первая таблица:'); p1(a,n,m); writeln('s,d:'); readln(s,d); writeln('Вторая таблица:'); p1(b,s,d); writeln('k1 = ',f1(a,n,m)); writeln('k2 = ',f1(b,s,d)); end.
#include <ctime>
int main()
{
using namespace std;
const int SIZE = 25;
int massive[SIZE];
//1й пункт
cout << "Enter number: ";
int num;
cin >> num;
int s = 0;
for (int i = 1; i <= num; i++)
if (num % i == 0)
if (i % 2 == 1)
s = s + i;
cout << "The sum of the odd divisors: " << s << endl;
//2й пункт
for (int i = 0; i < SIZE; i++)
{
cout << "Enter #" << i + 1 << " element: ";
cin >> massive[i];
}
for (int i = 0; i < SIZE; i++)
if (massive[i] < 0)
{
massive[i] = 0;
break;
}
for (int i = 0; i < SIZE; i++)
cout << massive[i] << ' ';
//3й пункт
for (int i = 0; i < SIZE; i++)
massive[i] = i + 1;
for (int i = 0; i < SIZE; i++)
if (massive[i] % 3 == 0)
massive[i] *= massive[2];
cout << endl;
for (int i = 0; i < SIZE; i++)
cout << massive[i] << ' ';
//4й пункт
srand(time(0));
for (int i = 0; i < SIZE; i++)
massive[i] = rand();
cout << endl;
for (int i = 0; i < SIZE; i++)
cout << massive[i] << ' ';
cout << endl;
cout << "Enter number: ";
int num2;
cin >> num2;
bool ifsum = false;
for (int i = 0; i < SIZE - 1; i++)
if (massive[i] + massive[i + 1] == num2)
{
ifsum = true;
break;
}
if (ifsum)
cout << "yes";
else
cout << "no";
cout << endl;
return 0;
}
Type marr = array [1..100,1..100] of real;
procedure p1(var x:marr;r1,r2:integer);
var i,j:integer;
begin
for i:=1 to r1 do
begin
for j:=1 to r2 do
begin
x[i,j]:=random(10);
write(x[i,j]:4);
end;
writeln;
end;
end;
function f1(var x:marr;r1,r2:integer):integer;
var i,j,k:integer;
begin
k:=0;
for i:=1 to r1 do
for j:=1 to r2 do
if (x[i,j]>=0)and(x[i,j]<=1) then k:=k+1;
f1:=k;
end;
Var a,b: marr; n,m,s,d: integer;
Begin
randomize;
writeln('n,m:');
readln(n,m);
writeln('Первая таблица:');
p1(a,n,m);
writeln('s,d:');
readln(s,d);
writeln('Вторая таблица:');
p1(b,s,d);
writeln('k1 = ',f1(a,n,m));
writeln('k2 = ',f1(b,s,d));
end.