Var ar:array[1..n] of integer; ar2:array[1..n] of integer; i,k:integer;
function prost(a:integer):boolean; var i:integer; b:boolean; begin b:=true; for i:=2 to a div 2 do if a mod i=0 then begin; b:=false; break; end; if a=1 then b:=false; prost:=b; end;
begin; randomize; k:=0; for i:=1 to n do begin; ar[i]:=random(101); write(ar[i]:4); end; writeln; for i:=1 to n do if prost(ar[i]) then begin; inc(k); ar2[k]:=ar[i]; write(ar2[k]:4); end; end.
Var m : array[0..6] of Integer; i,k,N : Integer; Begin For i:=0 to 6 do m[i]:=0; Readln(N); k:=6; While N>0 do Begin If N>=Power(2,k) then Begin N:=N-Trunc(Power(2,k)); Inc(m[k]); end else Dec(k); end; For i:=0 to 6 do Writeln(Power(2,i),' ',m[i],' шт.'); end.
Еще вариант: Const NN = 7; money : array[1..7] of Integer = (1,2,4,8,16,32,64); Var m : array[1..NN] of Integer; i,k,N : Integer; Begin For i:=1 to NN do m[i]:=0; Readln(N); k:=NN; While N>0 do Begin If N>=money[k] then Begin N:=N-money[k]; Inc(m[k]); end else Dec(k); end; For i:=1 to NN do Writeln(money[i],' ',m[i],' шт.'); end.
n=5;
Var
ar:array[1..n] of integer;
ar2:array[1..n] of integer;
i,k:integer;
function prost(a:integer):boolean;
var i:integer;
b:boolean;
begin
b:=true;
for i:=2 to a div 2 do
if a mod i=0 then
begin;
b:=false;
break;
end;
if a=1 then b:=false;
prost:=b;
end;
begin;
randomize;
k:=0;
for i:=1 to n do
begin;
ar[i]:=random(101);
write(ar[i]:4);
end;
writeln;
for i:=1 to n do
if prost(ar[i]) then
begin;
inc(k);
ar2[k]:=ar[i];
write(ar2[k]:4);
end;
end.
i,k,N : Integer;
Begin
For i:=0 to 6 do m[i]:=0;
Readln(N);
k:=6;
While N>0 do
Begin
If N>=Power(2,k) then
Begin
N:=N-Trunc(Power(2,k));
Inc(m[k]);
end else Dec(k);
end;
For i:=0 to 6 do Writeln(Power(2,i),' ',m[i],' шт.');
end.
Еще вариант:
Const
NN = 7;
money : array[1..7] of Integer = (1,2,4,8,16,32,64);
Var m : array[1..NN] of Integer;
i,k,N : Integer;
Begin
For i:=1 to NN do m[i]:=0;
Readln(N);
k:=NN;
While N>0 do
Begin
If N>=money[k] then
Begin
N:=N-money[k];
Inc(m[k]);
end else Dec(k);
end;
For i:=1 to NN do Writeln(money[i],' ',m[i],' шт.');
end.