/* C++ */ /*Массив заполняется случайными числами от -20 до 20*/ #include <iostream> #include <cstdlib> #include <ctime>
using namespace std;
int main() { setlocale(LC_ALL, "Russian"); int M[5][7], N[5][7]; int C[5], D[5]; int CountA, CountB; srand(time(NULL)); printf(" *** Массив M ***\n"); for (int i = 0; i < 5; i++) { CountA = 0; for (int j = 0; j < 7; j++) { M[i][j] = rand() % 41 - 20; if (M[i][j] < 0) CountA++; printf("%4d", M[i][j]); } C[i] = CountA; printf("\n"); } printf("\n"); printf(" *** Массив N ***\n"); for (int i = 0; i < 5; i++) { CountB = 0; for (int j = 0; j < 7; j++) { N[i][j] = rand() % 41 - 20; if (N[i][j] < 0) CountB++; printf("%4d", N[i][j]); } D[i] = CountB; printf("\n"); } printf("\n"); printf("*** Массив C ***\n"); for (int i = 0; i < 5; i++) printf("%8d\n", C[i]); printf("\n"); printf("*** Массив D ***\n"); for (int i = 0; i < 5; i++) printf("%8d\n", D[i]); printf("\n"); system("pause"); return 0; }
//================================================= //Pascal var M, N: array [1 .. 5, 1 .. 7] of integer; C, D: array [1 .. 5] of integer; i, j, CountA, CountB: integer; begin randomize; writeln(' ***** Массив M *****'); for i := 1 to 5 do begin CountA := 0; for j := 1 to 7 do begin M[i, j] := random(41) - 20; if M[i, j] < 0 then CountA := CountA + 1; write(M[i, j]:5); end; C[i] := CountA; writeln; end; writeln; writeln(' ***** Массив N *****'); for i := 1 to 5 do begin CountB := 0; for j := 1 to 7 do begin N[i, j] := random(41) - 20; if N[i, j] < 0 then CountB := CountB + 1; write(N[i, j]:5); end; D[i] := CountB; writeln; end; writeln; writeln('Массив C'); for i := 1 to 5 do writeln(C[i]:4); writeln; writeln('Массив D'); for i := 1 to 5 do writeln(D[i]:4); writeln; readln; end.
/*Массив заполняется случайными числами от -20 до 20*/
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
setlocale(LC_ALL, "Russian");
int M[5][7], N[5][7];
int C[5], D[5];
int CountA, CountB;
srand(time(NULL));
printf(" *** Массив M ***\n");
for (int i = 0; i < 5; i++)
{
CountA = 0;
for (int j = 0; j < 7; j++) {
M[i][j] = rand() % 41 - 20;
if (M[i][j] < 0) CountA++;
printf("%4d", M[i][j]);
}
C[i] = CountA;
printf("\n");
}
printf("\n");
printf(" *** Массив N ***\n");
for (int i = 0; i < 5; i++)
{
CountB = 0;
for (int j = 0; j < 7; j++) {
N[i][j] = rand() % 41 - 20;
if (N[i][j] < 0) CountB++;
printf("%4d", N[i][j]);
}
D[i] = CountB;
printf("\n");
}
printf("\n");
printf("*** Массив C ***\n");
for (int i = 0; i < 5; i++) printf("%8d\n", C[i]);
printf("\n");
printf("*** Массив D ***\n");
for (int i = 0; i < 5; i++) printf("%8d\n", D[i]);
printf("\n");
system("pause");
return 0;
}
//=================================================
//Pascal
var
M, N: array [1 .. 5, 1 .. 7] of integer;
C, D: array [1 .. 5] of integer;
i, j, CountA, CountB: integer;
begin
randomize;
writeln(' ***** Массив M *****');
for i := 1 to 5 do
begin
CountA := 0;
for j := 1 to 7 do
begin
M[i, j] := random(41) - 20;
if M[i, j] < 0 then CountA := CountA + 1;
write(M[i, j]:5);
end;
C[i] := CountA;
writeln;
end;
writeln;
writeln(' ***** Массив N *****');
for i := 1 to 5 do
begin
CountB := 0;
for j := 1 to 7 do
begin
N[i, j] := random(41) - 20;
if N[i, j] < 0 then CountB := CountB + 1;
write(N[i, j]:5);
end;
D[i] := CountB;
writeln;
end;
writeln;
writeln('Массив C');
for i := 1 to 5 do writeln(C[i]:4);
writeln;
writeln('Массив D');
for i := 1 to 5 do writeln(D[i]:4);
writeln;
readln;
end.