Types of integers are : integer, byte, word, longint, shortint.
Declaring Integers.
program int1;
var
a:integer;
b:byte;
c:word;
d:shortint;
f:longint;
begin
a:=1;
b:=2;
c:=3;
d:=4;
f:=5;
writeln('a = ',a);
writeln('b = ',b);
writeln('c = ',c);
writeln('d = ',d);
writeln('f = ',f);
end.
Reading integers from keyboard.
program int2;
var
a,b,c:integer;
begin
writeln('Key in a = ');
readln(a);
writeln('Key in b = ');
readln(b);
writeln('Key in c = ');
readln(c);
writeln('a = ',a);
writeln('b = ',b);
writeln('c = ',c);
end.
Operations using integers.
Declaring Integers.
program int1;
var
a:integer;
b:byte;
c:word;
d:shortint;
f:longint;
begin
a:=1;
b:=2;
c:=3;
d:=4;
f:=5;
writeln('a = ',a);
writeln('b = ',b);
writeln('c = ',c);
writeln('d = ',d);
writeln('f = ',f);
end.
Reading integers from keyboard.
program int2;
var
a,b,c:integer;
begin
writeln('Key in a = ');
readln(a);
writeln('Key in b = ');
readln(b);
writeln('Key in c = ');
readln(c);
writeln('a = ',a);
writeln('b = ',b);
writeln('c = ',c);
end.
Operations using integers.
1.Addition
2.Subtraction
3.Multiplication
4.Division
program int3;
program int3;
var
a,b,c:integer;
begin
writeln('Key in a = ');
readln(a);
writeln('Key in b = ');
readln(b);
writeln('Key in c = ');
readln(c);
writeln(a,' + ',b,' = ',a+b);
writeln(a,' - ',b,' = ',a-b);
writeln(a,' * ',b,' = ',a*b);
end.
a,b,c:integer;
begin
writeln('Key in a = ');
readln(a);
writeln('Key in b = ');
readln(b);
writeln('Key in c = ');
readln(c);
writeln(a,' + ',b,' = ',a+b);
writeln(a,' - ',b,' = ',a-b);
writeln(a,' * ',b,' = ',a*b);
end.
Integer Division
Integer division is expressed using DIV.
program int6;
var
a,b:integer;
begin
writeln('Give 2 integers: ');
readln(a,b);
writeln(a,' DIV ',b,' = ', a div b);
end.
The Modulus
The quotient of integer division: MOD
program int7;
var
a,b:integer;
begin
writeln('Give 2 integers: ');
readln(a,b);
writeln(a,' MOD ',b,' = ',a mod b);
end.
a,b:integer;
begin
writeln('Give 2 integers: ');
readln(a,b);
writeln(a,' MOD ',b,' = ',a mod b);
end.