// 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 "stdafx.h" #include <conio.h>
void swap(short &a, short &b) { short c = a; a = b;
b = c; }
void sort(short &a, short &b, short &c) { short min = a, max = c; if (min > b) min = b; if (min > c) min = c; if (max < a) max = a; if (max < b) max = b; b = a + b + c - min - max; a = min; c = max; }
if ((a1 == a2) && (b1 == b2) && (c1 == c2)) printf("Boxes are equal"); else if ((a1 <= a2) && (b1 <= b2) && (c1 <= c2)) printf_s("The first box is smaller than the second one"); else if ((a2 <= a1) && (b2 <= b1) && (c2 <= c1)) printf_s("The first box is larger than the second one"); else printf_s("Boxes are incomparable");
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.
#include "stdafx.h"
#include <conio.h>
void swap(short &a, short &b) {
short c = a;
a = b;
b = c;
}
void sort(short &a, short &b, short &c)
{
short min = a,
max = c;
if (min > b) min = b;
if (min > c) min = c;
if (max < a) max = a;
if (max < b) max = b;
b = a + b + c - min - max;
a = min;
c = max;
}
int main()
{
short a1, b1, c1, a2, b2, c2;
scanf_s("%hd %hd %hd", &a1, &b1, &c1);
scanf_s("%hd %hd %hd", &a2, &b2, &c2);
sort(a1, b1, c1);
sort(a2, b2, c2);
if ((a1 == a2) && (b1 == b2) && (c1 == c2))
printf("Boxes are equal");
else
if ((a1 <= a2) && (b1 <= b2) && (c1 <= c2))
printf_s("The first box is smaller than the second one");
else
if ((a2 <= a1) && (b2 <= b1) && (c2 <= c1))
printf_s("The first box is larger than the second one");
else
printf_s("Boxes are incomparable");
_getch();
return 0;
}