Const n=10; m=3; var a:array[1..n,1..m] of integer; i,j,s,k:integer; p:real; begin Randomize; writeln('Исходный массив:'); for i:=1 to n do begin for j:=1 to m do begin a[i,j]:=random(81)+20; write(a[i,j]:4); end; writeln; end; s:=0; for i:=1 to n do for j:=1 to m do s:=s+a[i,j]; p:=s/n*0.8; writeln('p = ',p:5:2); writeln('Зачислены:'); k:=0; for i:=1 to n do begin s:=0; for j:=1 to m do s:=s+a[i,j]; if s>=p then begin write(i,' '); k:=k+1; end; end; writeln; writeln('k = ',k); end.
'MS-DOS QBasic 1.0 DIM a(1 TO 20) AS SINGLE, b(1 TO 20) AS SINGLE CLS RANDOMIZE TIMER PRINT "Massiv a" j = 0 FOR i = 1 TO 20 a(i) = 10 * RND - 5 PRINT a(i); IF a(i) > 0 THEN j = j + 1 b(j) = a(i) END IF NEXT i FOR i = 1 TO 20 IF a(i) <= 0 THEN j = j + 1 b(j) = a(i) END IF NEXT i PRINT PRINT "Massiv b" FOR i = 1 TO j PRINT b(i); NEXT i PRINT
var
a:array[1..n,1..m] of integer;
i,j,s,k:integer; p:real;
begin
Randomize;
writeln('Исходный массив:');
for i:=1 to n do
begin
for j:=1 to m do
begin
a[i,j]:=random(81)+20;
write(a[i,j]:4);
end;
writeln;
end;
s:=0;
for i:=1 to n do
for j:=1 to m do s:=s+a[i,j];
p:=s/n*0.8;
writeln('p = ',p:5:2);
writeln('Зачислены:');
k:=0;
for i:=1 to n do
begin
s:=0;
for j:=1 to m do s:=s+a[i,j];
if s>=p then begin write(i,' '); k:=k+1; end;
end;
writeln;
writeln('k = ',k);
end.
Пример:
Исходный массив:
58 79 60
96 63 97
90 97 57
29 68 25
38 75 65
54 69 42
44 70 47
39 49 24
27 64 36
68 21 64
p = 137.20
Зачислены:
1 2 3 5 6 7 10
k = 7
DIM a(1 TO 20) AS SINGLE, b(1 TO 20) AS SINGLE
CLS
RANDOMIZE TIMER
PRINT "Massiv a"
j = 0
FOR i = 1 TO 20
a(i) = 10 * RND - 5
PRINT a(i);
IF a(i) > 0 THEN
j = j + 1
b(j) = a(i)
END IF
NEXT i
FOR i = 1 TO 20
IF a(i) <= 0 THEN
j = j + 1
b(j) = a(i)
END IF
NEXT i
PRINT
PRINT "Massiv b"
FOR i = 1 TO j
PRINT b(i);
NEXT i
PRINT
Тестовое решение:
Massiv a
-1.726111 1.835247 -4.176585 4.217188 4.836039 4.953975 .551706 .2788973
-1.588834 1.447831 1.91242 -3.830101 3.318729 1.483444 .0306803 -.3601742
1.934826 1.057516 -2.458627 .9090161
Massiv b
1.835247 4.217188 4.836039 4.953975 .551706 .2788973 1.447831 1.91242
3.318729 1.483444 .0306803 1.934826 1.057516 .9090161 -1.726111 -4.176585
-1.588834 -3.830101 -.3601742 -2.458627