PASCAL
Pascal - Data Types
Type Declarations
Var age : integer;
Var a,b : Real ;
Var name, city : string;
fees : real;
pass : boolean;
type
days, age = integer;
yes, true = boolean;
name, city = string;
fees, expenses = real;
var
weekdays, holidays : days;
choice: yes;
student_name, emp_name :
name;
capital: city;
cost: expenses;
age: integer = 15;
taxrate: real = 0.5;
grade: char = 'A';
name: string = 'John Smith';
program Greetings;
const
message = ' Welcome to the world of Pascal ';
type
name = string;
var
firstname, surname: name;
begin
writeln('Please enter your first name: ');
{get first name}
readln(firstname);
writeln('Please enter your surname: ');
readln(surname);
writeln;
writeln(message, ' ', firstname, ' ', surname);
end.
Constants
Const VELOCITY_LIGHT = 3.0 E=10;
Const PIE = 3.141592;
Const NAME = 'Stuart Little';
CHOICE = yes;
OPERATOR = '+';
program const_circle (input,output);
const
PI = 3.141592654;
var
r, d, c : real; {variable declaration: radius, dia,
circumference}
begin
writeln('Enter the radius of the circle');
readln(r);
d := 2 * r;
c := PI * d;
writeln('The circumference of the circle is
',c:7:2);
end.
program beLogical;
var
a, b: boolean;
begin
a := true;
b := false;
if (a and b) then
writeln('Line 1 - Condition is true' )
else
writeln('Line 1 - Condition is not true');
if (a or b) then
writeln('Line 2 - Condition is true' );
(* lets change the value of a and b *)
a := false;
b := true;
if (a and b) then
writeln('Line 3 - Condition is true' )
else
writeln('Line 3 - Condition is not true' );
if not (a and b) then
writeln('Line 4 - Condition is true' );
end.
program showRelations;
var
a, b: integer;
begin
a := 21;
b := 10;
if a = b then
writeln('Line 1 - a is equal to b' )
else
writeln('Line 1 - a is not equal to b' );
if a < b then
writeln('Line 2 - a is less than b' )
else
writeln('Line 2 - a is not less than b' );
if a > b then
writeln('Line 3 - a is greater than b' )
else
writeln('Line 3 - a is greater than b' );
(* Lets change value of a and b *)
a := 5;
b := 20;
if a <= b then
writeln('Line 4 - a is either less than or equal to b' );
if ( b >= a ) then
writeln('Line 5 - b is either greater than or equal to ' );
end.