Está en la página 1de 5

Exercises

1. What is the difference between a literal constant and a named constant?


Answer :
Literal constants are data values such as explicit numbers and text strings, while a named
constant is a “constant variable.”.
2. What is the difference between a named constant and a variable?
Answer
The difference between a named constant and a variable is that the value of the named
constant does not change during the program
A named constant is given a name and has to be declared in the declaration part.
Actually, the declaration part is divided into two sections, CONST and VAR; the
CONST section comes before the VAR section. Meanwhile the variable is
3. Write variable declarations, using the suitable data types, for the following items:
a. The price of a car in dollars and cents.
b. The surface area of a cylinder.
c. The number of students in a class.
Asnwer :
The price of a car in dollars and cents, we can use integer
The surface area of a cylinder, we can use Real
.The number of students in a class,we can use Integer number .

4. Write constant declarations for the following items:


a. A company name (provide a name of your own).
Answer :
{ ------------------------------- Example 1-9 ----------------------------- } PROGRAM
Constants(OUTPUT);
{ Constant Declarations }
CONST
Pi = 3.14159;
{ Variable Declarations }
Department= ‘ Candra education Center and Cendol World
VAR
Radius, Perimeter :REAL;
{ Program Block }
BEGIN
Radius := 4.9;
Perimeter := 2 * Pi * Radius;
WRITELN('Perimeter=', Perimeter)
END.

b. The conversion ratio from miles to kilometers.


{ ------------------------------- Example 1-9 ----------------------------- } PROGRAM
Constants(OUTPUT);
{ Constant Declarations }
CONST
Pi = 3.14159;
{ Variable Declarations }
VAR
Radius, Perimeter :REAL;
{ Program Block }
BEGIN
Radius := 4.9;
Perimeter := 2 * Pi * Radius;
WRITELN('Perimeter=', Perimeter)
END.
5. Write expressions to calculate the following items:
a. The area of a circle, given the radius.
Answer

{ ------------------------------- Example 1-9 ----------------------------- } PROGRAM


Constants(OUTPUT);
{ Constant Declarations }
CONST
Pi = 3.14159;
{ Variable Declarations }
VAR
Radius, Perimeter :REAL;
{ Program Block }
BEGIN
Radius := 4.9;
Perimeter := 2 * Pi * Radius;
WRITELN('Perimeter=', Perimeter)
END.

b. A student’s total grade in three classes.


{ ------------------------------- Example 1-9 ----------------------------- } PROGRAM
Constants(OUTPUT);
{ Constant Declarations }
CONST
Total student = 3;
{ Variable Declarations }
VAR
Radius, Perimeter :REAL;
{ Program Block }
BEGIN
Radius := 4.9;
Perimeter := 2 * Pi * Radius;
WRITELN('Perimeter=', Perimeter)
END.
c. The price of an item including an 8% tax.
{ ------------------------------- Example 1-9 ----------------------------- } PROGRAM
Constants(OUTPUT);
{ Constant Declarations }
CONST
tax = 0.08 ;
{ Variable Declarations }
VAR
Radius, Perimeter :REAL;
{ Program Block }
BEGIN
Radius := 4.9;
Perimeter := 2 * Pi * Radius;
WRITELN('Perimeter=', Perimeter)
END.
6. Evaluate the following expressions:
a. 10 + 5 * 2 - 6 / 2
10 + 5* 2 - 6 DIV 2
20 DIV 2
10

b. (10 + 5) * 2 - 6 / 2
(10 +5) * 2-6 DIV 2
15*2-6 DIV 2
30-6 DIV 2
30-3
27

c. (10 + 5 * 2 - 6) / 2
(10 + 5 * 2 - 6) DIV 2
14 DIV 2
7

d. ((10 + 5) * 2 - 6) / 2
((10 + 5) * 2 - 6) DIV 2
24 DI 2
12

7. Write a Pascal program to print your name, home address, and e-mail, each on a
separate line.
BEGIN
WRITE('hello good people ');
WRITELN('we are group three?');
WRITELN('the member of group
three is candra muktamar
END.

8. Evaluate the following expressions:


a. 1.0/2.0 e. 1 MOD 2
b. 1.0/2 f. 10 / 3
c. 1/2 g. ROUND(10/3)
d. 1 DIV 2

answer

PROGRAM Arithmetic(OUTPUT); { Variable Declarations }


VAR
A : INTEGER;,
b :INTEGER;
{ Program Block }
BEGIN
a := 1.0;
b := 20;
writeln ( ‘a/b ‘);
End.

PROGRAM Arithmetic(OUTPUT); { Variable Declarations }


VAR
A : INTEGER;,
b :INTEGER;
{ Program Block }
BEGIN
a := 1.0;
b := 2;
writeln ( ‘a/b ‘);
End.
PROGRAM Arithmetic(OUTPUT); { Variable Declarations }
VAR
A : INTEGER;,
b :INTEGER;
{ Program Block }
BEGIN
a := 1;
b := 2;
writeln ( ‘a/b ‘);
End.

PROGRAM Arithmetic(OUTPUT); { Variable Declarations }


VAR
A : INTEGER;,
b :INTEGER;
{ Program Block }
BEGIN
a := 1;
b := 2;
writeln ( ‘a DIV b ‘);
End.

PROGRAM Arithmetic(OUTPUT); { Variable Declarations }


VAR
A : INTEGER;,
b :INTEGER;
{ Program Block }
BEGIN
a := 1;
b := 2;
writeln ( ‘a MOD b ‘);
End.
PROGRAM Arithmetic(OUTPUT); { Variable Declarations }
VAR
A : INTEGER;,
b :INTEGER;
{ Program Block }
BEGIN
a := 10;
b := 3;
writeln ( ‘a / b ‘);
End.
PROGRAM Arithmetic(OUTPUT); { Variable Declarations }
VAR
A : INTEGER;,
b :INTEGER;
{ Program Block }
BEGIN
a := 1;
b := 2;
writeln ( ‘a DIV b ‘);
WRITELN('Perimeter (rounded)=', RoundedPerimeter);

End.

También podría gustarte