Data Types, Vatriables & Aritmatic
 

program Integer_Variable_Demo;

var Count : integer;
X,Y : integer;

begin
X := 12;
Y := 13;
Count := X + Y;
Writeln('The value of X is',X:4);
Writeln('The value of Y is',Y:5);
Writeln('And Count is now ',Count:6);
end.


Result of execution

The value of X is 12
The value of Y is 13
And Count is now 25


program More_Integer_Demos;

var X,Y : integer;
Count : integer;

begin
X := 12;
Y := 13;
Count := X + Y;
Write('The value of X is');
Writeln(X:4);
Write('The value of Y is');
Writeln(Y:5);
Write('And Count is now ');
Write(Count:6);
Writeln;
end.



Result of execution

The value of X is 12
The value of Y is 13
And Count is now 25


program All_Simple_Variable_Types;

var A,B : integer;
C,D : byte;
Dog_Tail : real;
Puppy : boolean;
Animal_Cookies : char;

begin
A := 4;
B := 5;
C := 212;
D := C + 3;
Dog_Tail := 345.12456;
Puppy := B > A; (* since B is greater than A, Puppy
will be assigned the value TRUE *)
Animal_Cookies := 'R'; (* this is a single character *)

Writeln('The integers are',A:5,B:5);
Writeln('The bytes are', C:5,D:5); (* notice that the spaces
prior to the C will be
ignored on output *)
Writeln('The real value is',Dog_Tail:12:2,Dog_Tail:12:4);
Writeln;
Writeln('The boolean value is ',Puppy,Puppy:13);
Writeln('The char variable is an ',Animal_Cookies);
end.



Result of execution

The integers are 4 5
The bytes are 212 215
The real value is 345.12 345.1246

The boolean value is TRUE TRUE
The char variable is an R


(c) Shilpa Sayura Foundation 2006-2017