Book of tasks on programming. Old version

 

 by Aliaksandr N. Prykhodzka

 

row, FAT32, computer, applet, unit, breakpoint, итерация, Excel, public, xml, in, list, logic, object, выполнимый, реассемблирование, answers, publishing house
 

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

Pascal. Pa.22. Nest of tasks. Sequences

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.1     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y, z : integer;
begin
    z:=0;    x:=0;    y:=1;
    repeat
        z:=z+1;    x:=x+3;    y:=y*2+1;
        if z mod 2 = 0 then writeln(x)
        else writeln(y);
    until z=7;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.2     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y, z : integer;
begin
    z:=0;        x:=0;        y:=1;
    repeat
        z:=z+1;    x:=x*2+1;    x:=x mod 100;
        y:=y*3+2;    y:=y mod 100;
        if z mod 3 = 0 then writeln(x)
        else writeln(y);
    until z=6;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.3     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y, z : integer;
begin
    z:=0;        x:=0;        y:=1;
    while y<>9 do begin
        z:=z+1;    x:=x*3+2;    y:=y*2-1;
        if z mod 4 = 0 then writeln(x)
        else writeln(y);
    end;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.4     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y, z : integer;
begin
    x:=0;        y:=1;
    for z:=1 to 7 do begin
        x:=(x+2)*3;        y:=y*3-2;
        if z mod 2 = 0 then writeln(x)
        else writeln(y);
    end;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.5     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y, z : integer;
begin
    x:=0;        y:=1;
    for z:=1 to 8 do begin
        x:=(x+1)*2;        y:=(y+4)*2;
        if z div 3 < 2 then writeln(x)
        else writeln(y);
    end;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.6     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    z : integer;
    x, y : boolean;
begin
    x:=false;    y:=true;
    for z:=1 to 8 do begin
        x:=not (x or (z mod 2 = 0));
        y:=not (x or y);
        if z mod 3 = 0 then writeln(x)
        else writeln(y);
    end;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.7     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y, z : integer;
begin
    for x:=1 to 5 do begin
        y:=x*2-1;    z:=y mod 3;
        writeln(z);
    end;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.8     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x : integer;
begin
    for x:=5 to 10 do begin
        if x mod 2 = 0 then writeln(x);
        if x mod 3 = 0 then writeln(x);
        if x mod 4 = 0 then writeln(x);
    end;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.9     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y : integer;
begin
    for x:=1 to 5 do
        for y:=x div 2 to x do writeln(y);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.10     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y : integer;
begin
    y:=1;        x:=0;
    repeat
        y:=y*2-1;
        if y mod 3 = 0 then begin
            x:=x+1;
            writeln(y);
        end;
    until x=5;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.11     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y : integer;
begin
    y:=0;        x:=0;
    while x<5 do begin
        y:=y+2;
        if y mod 3 = 0 then begin
            x:=x+1;
            writeln(y);
        end;
    end;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.12     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y : integer;
begin
    y:=100;    x:=1;
    while x<5 do begin
        x:=x+1;    y:=y div 2;
        writeln(y);
    end;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.13     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y : integer;
begin
    y:=1;        x:=1;
    while x<4 do begin
        x:=x+1;    y:=y*3;
        writeln(y);
    end;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.14     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y, z : integer;
begin
    x:=10;    y:=35;    z:=1;
    while x         z:=z+1;
        if z mod 2 = 0 then writeln(x)
        else writeln(y);
        x:=x+2;    y:=y-3;
    end;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.15     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y, z : integer;
    M : array[1..8] of integer;
begin
    for x:=1 to 8 do M[x]:=x;
    for x:=1 to 4 do begin
        y:=x*2;    z:=y-1;
        writeln(M[y]);
        writeln(M[z]);
    end;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.16     Answer

Determine values of four first integer or boolean variables produced by this program


Program AA;
var
    x, y, z : integer;
    M : array[1..10] of boolean;
begin
    for x:=1 to 10 do M[x]:=(x div 3 = 0);
    for y:=1 to 10 do begin
        z:=11-y;
        writeln(M[z]);
    end;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.17     Answer

Determine a sequence of numbers produced by this program


Program AA;
var
    x, y : integer;
begin
    y:=0;        x:=0;
    while x<5 do begin
        y:=y+2;
        if y mod 3 = 0 then begin
            x:=x+1;
            writeln(y);
        end;
    end;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.22.18     Answer

Determine programs which produce the sequence of values True, False, True, True, False. Enumerate names of these programs.


Program uu1;
var
      i : integer;
      bb : boolean;
begin
      for i:=1 to 5 do begin
            bb:=(i mod 2=1) or (i mod 4=0);
            writeln(bb);
      end
end.

Program uu2;
var
      i : integer;
      bb : boolean;
begin
      for i:=1 to 10 do
            if i mod 2=0 then begin
                  bb:=(i mod 4=2) or (i mod 8=0);
                  writeln(bb);
            end;
end.

Program uu3;
var
      i : integer;
      bb : boolean;
begin
      for i:=11 to 15 do begin
            bb:=(i div 5 > 1) and (i mod 2=1);
            writeln(bb);
      end;
end.

Program uu4;
var
      bb, cc :      boolean;
      k :      integer;
begin
      bb:=True;
      cc:=True;
      k:=0;
      while k<4 do begin
            k:=k+1;
            if k=4 then writeln(cc);
            writeln(bb);
            bb:=not bb;
      end;
end.

 

©   Aliaksandr Prykhodzka    1993 - 2007