Book of tasks on programming. Old version

 

 by Aliaksandr N. Prykhodzka

 

function, десятичный, byte, on-line, MYSQL, with, object, граф, probleme, word, applet, path, сохраненная процедура, const, bit, calculator, диаграмма, memory
 

for valuable work you must have JavaScript (allow active content)

Pascal. Pa.5. Nest of tasks. Labels and operator goto

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.1     Answer

Determine a values produced by this program


Program Pr;
label xxx;
begin
    writeln(1);
    writeln(2);
    goto xxx;
    writeln(3);
    writeln(4);
xxx:
    writeln(5);
    writeln(6);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.2     Answer

Determine a values produced by this program


Program Pr;
label xxx;
begin
    writeln(1);
    goto xxx;
    writeln(2);
    writeln(3);
    writeln(4);
xxx:
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.3     Answer

Determine a values produced by this program


Program Pr;
label xxx;
begin
    goto xxx;
    writeln(1);
    writeln(2);
    writeln(3);
    writeln(4);
xxx:
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.4     Answer

Determine a values produced by this program


Program Pr;
label xxx;
var
    t : integer;
begin
    t:=0;
xxx:
    t:=t+1;
    writeln(t);
    if t<4 then goto xxx;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.5     Answer

Determine a values produced by this program. (Pithy content of task: find a sum of numbers)


Program Pr;
label xxx;
var
    s, t : integer;
begin
    s:=0; t:=0;
xxx:
    t:=t+1; s:=s+t;
    if t<4 then goto xxx;
    writeln(s);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.6     Answer

Determine a values produced by this program. (Pithy content of task: find a production of numbers)


Program Pr;
label xxx;
var
    s, t : integer;
begin
    s:=1; t:=0;
xxx:
    t:=t+1; s:=s*t;
    if t<5 then goto xxx;
    writeln(s);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.7     Answer

Determine a values produced by this program. (Pithy content of task: find how many are numbers starting with 1 and production of them is not less than 10)


Program Pr;
label xxx;
var
    s, t : integer;
begin
    s:=1; t:=0;
xxx:
    t:=t+1; s:=s*t;
    if s<10 then goto xxx;
    writeln(t);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.8     Answer

Determine a values produced by this program. (Pithy content of task: find how many are numbers starting with 1 and production of them is not less than 30)


Program Pr;
label xxx;
var
    s, t : integer;
begin
    s:=1; t:=0;
xxx:
    t:=t+1; s:=s*t;
    if s<30 then goto xxx;
    writeln(t);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.9     Answer

Determine a values produced by this program. (Pithy content of task: find how many are numbers starting with 1 and sum of them is not less than 10)


Program Pr;
label xxx;
var
    s, t : integer;
begin
    s:=0; t:=0;
xxx:
    t:=t+1; s:=s+t;
    if s<10 then goto xxx;
    writeln(t);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.10     Answer

Determine a values produced by this program. (Pithy content of task: find how many are numbers starting with 1 and sum of them is not less than 30)


Program Pr;
label xxx;
var
    s, t : integer;
begin
    s:=0; t:=0;
xxx:
    t:=t+1; s:=s+t;
    if s<30 then goto xxx;
    writeln(t);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.11     Answer

Determine a values produced by this program. (Pithy content of task: find first number divisible by 2 and 3)


Program Pr;
label aaa;
var
    t : integer;
begin
for t:=1 to 10 do
        if (t mod 2=0) and (t mod 3=0) then begin
            writeln(t);
            goto aaa;
        end;
aaa:
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.12     Answer

Determine a values produced by this program. (Pithy content of task: find first number divisible by 7 and 3)


Program Pr;
label aaa;
var
    t : integer;
begin
    for t:=1 to 100 do
        if (t mod 7=0) and (t mod 3=0) then begin
            writeln(t);
            goto aaa;
        end;
aaa:
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.13     Answer

Determine a values produced by this program. (Pithy content of task. We have two packets of meal.
The mass of two packets is 10 kg. The mass of first packet is the mass of second packet plus 2 kg.
Determine the mass of first and of seconds packets. Task is solved by trying all possible values.



Program Pr;
label aaa;
var
    x, y : integer;
begin
    for x:=1 to 100 do
        for y:=1 to 100 do
            if (x+y=10) and (x=y-2) then begin
                writeln(x);
                writeln(y);
                goto aaa;
            end;
aaa:
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.14     Answer

Determine a values produced by this program. (Pithy content of task. We have two packets of meal.
The mass of two packets is 15 kg. The mass of first packet is the mass of second packet twice.
Determine the mass of first and of seconds packets. Task is solved by trying all possible values.




Program Pr;
label aaa;
var
    x, y : integer;
begin
    for x:=1 to 100 do
    for y:=1 to 100 do
        if (x+y=15) and (x=y*2) then begin
            writeln(x);
            writeln(y);
            goto aaa;
        end;
aaa:
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.15     Answer

Determine a values produced by this program. (Pithy content of task. There are three strems over meadow. The total length of streams is 20 miles. The length of first stream is equal to the length of second stream plus the length of third stream. The length of second stream is the length of third stream plus four miles. Determine length of all streams. Task is solved by trying all possible values.



Program Pr;
label aaa;
var
    x, y, z : integer;
begin
    for x:=1 to 100 do
        for y:=1 to 100 do
            for z:=1 to 100 do
                if (x+y+z=20) and (x=y+z) and (y=z+4) then begin
                    writeln(x);
                    writeln(y);
                    writeln(z);
                    goto aaa;
                end;
aaa:
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.5.16     Answer

Determine a values produced by this program. (Pithy content of task. There are three strems over meadow. The total length of streams is 35 miles. The length of first stream is equal to the length of second stream twice. The length of second stream is the length of third stream plus five miles. Determine length of all streams. Task is solved by trying all possible values.




Program Pr;
label aaa;
var
    x, y, z : integer;
begin
    for x:=1 to 100 do
        for y:=1 to 100 do
            for z:=1 to 100 do
                if (x+y+z=35) and (x=2*y) and (y=z+5) then begin
                    writeln(x);
                    writeln(y);
                    writeln(z);
                    goto aaa;
                end;
aaa:
end.

 

©   Aliaksandr Prykhodzka    1993 - 2007