// 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.
Вопрос скорее будет звучать "как много могли съесть толстяки?".
#include <iostream>
using namespace std;
int main() {
int multiplier = 1;
float weightCake = 0;
float t1(0), t2(0), t3(0);
float t1Cakes(0), t2Cakes(0), t3Cakes(0);
cout << "Weight of cake, fat people 1-3: ";
cin >> weightCake; cin >> t1; cin >> t2; cin >> t3;
while(1) {
t1Cakes = multiplier * weightCake * 1;
if(t1Cakes > t1/2) {
cout << multiplier - 1;
break;
}
t2Cakes = multiplier * weightCake * 2;
if(t2Cakes > t2/2) {
cout << multiplier - 1;
break;
}
t3Cakes = multiplier * weightCake * 4;
if(t3Cakes > t3/2) {
cout << multiplier - 1;
break;
}
++multiplier;
}
}
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.