Const n=5; var a:array[1..5,1..5] of integer; i,j,k:integer; begin Randomize; Writeln('Исходный массив'); k:=0; for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=Random(100)+1; Write(a[i,j]:4); if a[i,j] mod 5 = 0 then k:=k+1 end; Writeln end; Writeln('Количество элементов, кратных 5, равно ',k) end.
#include <stdio.h>#include <time.h> int main(void) { int left, right, num = 5; time_t t;
scanf ("%d %d", &left, &right);
if(left >= right) { fprintf(stderr, "min_num is greater or equal than max_num!\n"); }
printf ("left = %d right = %d \n", left, right); /* Intializes random number generator */ srand((unsigned) time(&t)); /* Print num random numbers from left to right */ while (num > 0) { printf ( "%d ", left + (rand() % (right + 1 - left)) ); num--; } return 0;}
n=5;
var
a:array[1..5,1..5] of integer;
i,j,k:integer;
begin
Randomize;
Writeln('Исходный массив');
k:=0;
for i:=1 to n do
begin
for j:=1 to n do
begin
a[i,j]:=Random(100)+1;
Write(a[i,j]:4);
if a[i,j] mod 5 = 0 then k:=k+1
end;
Writeln
end;
Writeln('Количество элементов, кратных 5, равно ',k)
end.
Контрольный пример
Исходный массив
82 100 2 68 88
31 75 21 18 7
100 65 23 80 27
1 88 49 94 93
50 87 77 67 80
Количество элементов, кратных 5, равно 7
int main(void) { int left, right, num = 5; time_t t;
scanf ("%d %d", &left, &right);
if(left >= right) { fprintf(stderr, "min_num is greater or equal than max_num!\n"); }
printf ("left = %d right = %d \n", left, right);
/* Intializes random number generator */ srand((unsigned) time(&t));
/* Print num random numbers from left to right */ while (num > 0) { printf ( "%d ", left + (rand() % (right + 1 - left)) ); num--; }
return 0;}