Book of tasks on programming. Old version

 

 by Aliaksandr N. Prykhodzka

 

учебник, сортировка, constructor, трассировка, pointer, объяснения, offline, чайник, type, ссылка, пролог, метод, string, object, set, абстрактный, function
 

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

Pascal. Pa.27. Nest of tasks. Tasks on slicing

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.1     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b, c, s1, s2, tt : integer;
begin
    readln(a);    readln(b);    readln(c);
    s1:=a+b;    s2:=b+c;    tt:=s1+b;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.2     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b, tt : integer;
begin
    readln(a);    readln(b);
    tt:=a*a;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.3     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b, tt : integer;
begin
    a:=5;        b:=7;
    a:=a*a;    tt:=b-4;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.4     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b, c, d, s1, s2, s3, tt : integer;
begin
    readln(a);    readln(b);
    readln(c);    readln(d);
    s1:=a+b;
    s2:=b+c;
    s3:=c+d;
    tt:=s3-s1;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.5     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b, c, d, s1, s2, tt : integer;
begin
    readln(a);    readln(b);
    readln(c);    readln(d);
    s1:=a+b+c;
    s2:=b+c+d;
    tt:=s1+s2;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.6     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b1, b2, b3, tt : integer;
begin
    readln(a);
    b1:=a;    b2:=a*a;    b3:=a*a*a;
    tt:=b1+b2+b3;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.7     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b, c, tt : integer;
begin
    readln(a);    readln(b);
    if a>b then c:=a+b
    else c:=a-b;
    tt:=a+b;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.8     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b, c, d, tt : integer;
begin
    readln(a);    readln(b);
    c:=0;
    for d:=1 to a do c:=c+b;
    tt:=a+b;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.9     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b, c, d, tt : integer;
begin
    readln(a);    readln(b);
    c:=0;
    for d:=1 to a do c:=c+b;
    tt:=a+c;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.10     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b, c, d, tt : integer;
begin
    readln(a);    readln(b);
    c:=0;
    for d:=1 to a do c:=c+a;
    tt:=c+a;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.11     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    i, a, b, c, tt : integer;
begin
    c:=0;
    for i:=1 to 3 do begin
        a:=i+c; b:=a*a; c:=a+3;
    end;
    tt:=c+5;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.12     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    i, a, c, tt : integer;
begin
    tt:=0;    c:=5;
    for i:=1 to 3 do begin
        a:=i+c;    tt:=tt+a;
    end;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.13     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    tt, a, i : integer;
begin
    tt:=0;    a:=0;
    for i:=1 to 7 do a:=a+3;
    tt:=tt+a;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.14     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    tt, i : integer;
begin
    tt:=0;
    for i:=1 to 7 do tt:=tt+i;
    tt:=51;
    while tt>3 do tt:=tt div 3;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.15     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a1, a2, a3, a4, a5, a6, tt : integer;
begin
    a1:=1;    a2:=2;
    a3:=a1+a2;    a4:=a2+10;
    a5:=a2+a3;    a6:=a1*a1;
    tt:=a4-a6;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.16     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b, c, tt : integer;
begin
    a:=9;        b:=19;
    if a>b then c:=1 else c:=5;
    tt:=a-b;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.17     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b, c, d, tt : integer;
begin
    a:=7;        b:=17;
    c:=0;
    if a>b then c:=a+b else d:=a*b;
    tt:=a+d;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.18     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b, c, x, tt : integer;
begin
    a:=7;        b:=19+a;
    c:=a*a;    c:=c+a;
    while c>a do begin
        x:=x+c;    a:=a-1;
    end;
    tt:=x*x;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.19     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, tt : integer;
begin
    readln(a);    tt:=4;
    if a=1 then a:=2
    else
        if a=2 then a:=3
        else
            if a=3 then a:=4
            else
                if a=4 then tt:=55;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.20     Answer      Java-analogue      Visual Basic-analogue

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, tt : integer;
begin
    readln(a);    tt:=4;
    if a>50 then a:=50
    else
        if a>40 then a:=40
        else
            if a>30 then a:=30
            else
                if a>20 then tt:=5
                else tt:=6;
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.21     Answer

Enumerate operators which don't affect the variable tt at the end of program


Program AA;
var
    a, b, c, d, tt : integer;
begin
    repeat
        readln(a);    readln(b)
    until b>10;
    c:=5;        d:=8;        tt:=a+d;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.22     Answer

Enumerate operators which don't affect the variable tt at the end of program


Program AA:
var
    a, b, c, tt : integer;
begin
    repeat
        readln(a);
        repeat
            readln(b);    readln(c)
        until a>c;
    until a>20;
    tt:=a+c;
    writeln(tt);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.23     Answer      Java-analogue      Visual Basic-analogue

Delete unnecessary operators to produce the program of finding maximum element in array.


program It_is_always_darkest_before_the_dawn;
var
    i, tt, aa, bb : integer;
    A : array[1..10] of integer;
begin
    for i:=1 to 10 do readln(A[i]);
    tt:=A[1];    aa:=A[1];    bb:=A[1];
    for i:=2 to 10 do begin
        if A[i]>tt then tt:=A[i];
        if A[i]=aa then aa:=A[i];
        if A[i]     end;
    writeln(tt);    writeln(aa);    writeln(bb);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.24     Answer      Java-analogue      Visual Basic-analogue

Delete unnecessary operators to produce the program of finding maximum element in array.


program Actions_speak_louder_than_words;
var
    i, tt, aa, bb : integer;
    A : array[1..10] of integer;
begin
    for i:=1 to 10 do readln(A[i]);
    tt:=A[1];    aa:=A[1];    bb:=A[1];
    for i:=2 to 10 do begin
        if A[i]>tt then tt:=A[i]
        else
            if A[i]=aa then aa:=A[i]
            else
                if A[i]     end;
    writeln(tt);    writeln(aa);    writeln(bb);
end.

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

Pa.27.25     Answer      Java-analogue

Delete unnecessary operators to produce the program of finding maximum element in array.


program An_apple_a_day_keeps_the_doctor_away;
var
    tt : integer;
    Dragon : array[1..10] of integer;
    i, j, k : integer;
begin
    Randomize;
    for i:=1 to 10 do readln(Dragon[i]);
    tt:=Dragon[10];
    for i:=1 to 10 do
        if Dragon[i]>tt then tt:=Dragon[i];
    while Dragon[10]>0 do begin
        for i:=9 downto 1 do
            Dragon[i+1]:=Dragon[i+1]-Dragon[i];
        for i:=9 downto 1 do
            for j:=1 to i do
                if Dragon[j]>Dragon[j+1] then begin
                    k:=Dragon[j];
                    Dragon[j]:=Dragon[j+1];
                    Dragon[j+1]:=k
                end;
        Dragon[10]:=Dragon[9]
    end;
    writeln(tt);
end.

 

©   Aliaksandr Prykhodzka    1993 - 2007