0% found this document useful (0 votes)
208 views

Coding Exercise

The document contains snippets of Pascal code from various programs. The code snippets demonstrate different programming concepts like variables, conditionals, loops, functions and procedures.

Uploaded by

GabrielaAmanda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
208 views

Coding Exercise

The document contains snippets of Pascal code from various programs. The code snippets demonstrate different programming concepts like variables, conditionals, loops, functions and procedures.

Uploaded by

GabrielaAmanda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

TES1.PAS TES2C.

PAS
Program Coba; Program Coba;
Var a , b : integer; Var a , b : integer;
Begin Begin
a := 5; {1} a := 5; {1}
b := 10; {2} b := 8;
writeln; {3} if a > b then {2}
end. a := 2 {3}
else
b := a;
end.

TES2D.PAS TES3.PAS
Program Coba; Program Coba;
Var a , b : integer; var a : integer;
Begin begin
A := 5; {1} a := 5;
If a > 3 then {2} while a < 10 do
a := 2; begin
writeln(a); a := a + 1;
end. end;
a := a + 10;
writeln;
end.

TES4.PAS TES5.PAS
Program Coba; Program Coba;
Var a : integer; Var a : integer;
Begin Begin
for a := 5 to 10 do a := 5;
begin repeat
writeln(a); a := a + 1;
end; until a > 10;
writeln; a := a + 20;
end. writeln;
end.

TES7.PAS TES8.PAS
Program Coba; Program Coba;
var a , b, c : integer; var a : integer;
begin begin
a := 5; a := 5;
b := 8; while a < 10 do
c := 4; begin
if (a > b) or (a > c)then if a > 5 then
begin writeln(a);
a := 2; a := a + 1;
end end;
else a := a + 10;
begin writeln;
if b = a then end.
b := a
else
b := c;
end;
readln;;
end.

Uji Kualitas/ Bayu Hendradjaya/ 02/12/03


TES9.PAS TES10.PAS
Program Coba; Program Coba;
var a, b : integer; Var a, b : integer;
begin Begin
readln (b); Readln (a);
for a := 1 to 10 do Repeat
begin if a > 3 then
if a > b then writeln(a) writeln(a);
else writeln(b); a := a + 1;
end; until a > 5;
writeln(a, b); writeln(a);
end. end.

TES11.PAS TES12.PAS
Program Coba; Program Coba;
Var a, b : integer; var a : integer;
Begin begin
Readln (a, b); a := 5;
Case a of if a > 4 then
1 : if a > b then begin
writeln(a); while a < 10 do
2 : if a < b then begin
writeln(b); if a > 5 then
end; writeln(a);
writeln(a, b); a := a + 1;
end. end;
end
else
a := a + 10;
writeln;
end.

TES27.PAS ALGO19.PAS
Program Coba; Program BinomialCoefficients;
var a , b, c : integer; Var
begin i, a, b : integer;
a := 5; m, n : integer;
b := 8; begin
c := 4; readln( m, n );
if a > b then a := 1;
begin if 2 * m > n then
a := 2; b := n - m
end else
else b := m;
begin i := 0;
case b of while i <= b do
1 : b := a; begin
2 : b := a + 1; a := (n - i ) * a + (i +1);
else i := i + 1;
b := c; end;
end; writeln( a );
end; end.
writeln(a,b);
end.

Uji Kualitas/ Bayu Hendradjaya/ 02/12/03


ALGO106.PAS
Program ComplexNumberToARealPower;
Var
x, y, w, A, B : real;
theta, phi, r : real;
begin
readln( x, y, w, A, B );
if x > 0 then
begin
theta := 0.0;
phi := arctan(y/x)+theta;
r := sqrt( x*x+y*y );
r := exp( w * ln(r));
a := r * cos( w * phi);
b := r * sin( w * phi);
end;

if (x < 0) and (y >= 0) then


begin
theta := 3.1;
phi := arctan(y/x)+theta;

r := sqrt( x*x+y*y );
r := exp( w * ln(r));
a := r * cos( w * phi);
b := r * sin( w * phi);
end;
if (x<0) and (y<0) then
begin
theta := 3.1;
phi := arctan(y/x)+theta;

r := sqrt( x*x+y*y );
r := exp( w * ln(r));
a := r * cos( w * phi);
b := r * sin( w * phi);
end;
if (x=0) and (y= 0) then
begin
a := 0.0;
b := 0.0;
end;

if (x = 0) and (y < 0) then


begin
phi := 1.5;
r := sqrt( x*x+y*y );
r := exp( w * ln(r));
a := r * cos( w * phi);
b := r * sin( w * phi);
end;

if (x = 0) and (y > 0) then


begin
phi := -1.5707963;
r := sqrt( x*x+y*y );
r := exp( w * ln(r));
a := r * cos( w * phi);
b := r * sin( w * phi);
end;
writeln(a,b)
end.

Uji Kualitas/ Bayu Hendradjaya/ 02/12/03

You might also like