// PascalABC.NET 3.1, сборка 1200 от 13.03.2016 begin var a:=MatrixRandom(7,7,0,9); var k:=0; for var i:=0 to 6 do begin for var j:=0 to 6 do begin Write(a[i,j]:3); if a[i,j] in [1..5] then Inc(k) end; Writeln end; Writeln('Кол-во элементов на [1,5]: ',k) end.
const n=7; var a:array[1..n,1..n] of integer; i,j,k:integer; begin Randomize; k:=0; for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=Random(10); Write(a[i,j]:3); if a[i,j] in [1..5] then Inc(k) end; Writeln end; Writeln('Кол-во элементов на [1,5]: ',k) end.
begin
var a:=MatrixRandom(7,7,0,9);
var k:=0;
for var i:=0 to 6 do begin
for var j:=0 to 6 do begin
Write(a[i,j]:3);
if a[i,j] in [1..5] then Inc(k)
end;
Writeln
end;
Writeln('Кол-во элементов на [1,5]: ',k)
end.
Тестовое решение:
2 1 7 3 3 2 7
9 2 9 2 0 5 5
4 2 6 9 4 6 0
1 0 3 5 4 5 9
6 3 6 0 2 0 8
0 8 4 3 2 1 8
6 0 4 4 5 4 0
Кол-во элементов на [1,5]: 27
Вариант "совсем для школы"
const
n=7;
var
a:array[1..n,1..n] of integer;
i,j,k:integer;
begin
Randomize;
k:=0;
for i:=1 to n do begin
for j:=1 to n do begin
a[i,j]:=Random(10);
Write(a[i,j]:3);
if a[i,j] in [1..5] then Inc(k)
end;
Writeln
end;
Writeln('Кол-во элементов на [1,5]: ',k)
end.
import java.util.*;
import java.io.*;
public class Main {
static int _16yearsOld = 0;
static int min = 14;
static int max = 16;
static int diff = max - min;
static Random random = new Random();
static int rand = random.nextInt(diff + 1);
rand += min;
public static void main(string[] args) {
int[] students = new int[19];
for (int i = 0; i <= students.size(); i++) {
students[i] = rand;
}
for (int i = 0; i <= students.size(); i++) {
if (students[i] == 16)
_16yearsOld++;
}
}
}
Объяснение: