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

Pascal

Uploaded by

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

Pascal

Uploaded by

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

ICT - O/L

Pascal - පැස්කල්

Pascaline
01. program Hello; 02. program Hello;
begin uses crt;
writeln(‘Hello World!’); begin
readln; clrscr;
end. writeln(‘Hello world!’);
readln;
end.

03.
program Hello;
uses crt;
var m: String;
begin
clrscr;
write('Enter your name: ');
readln(m);
writeln('Hello ', m);
writeln('Welcome to pascal programming');
readln;
end.

04.
program Algebra(input, output);
uses crt;
begin
clrscr;
{Algebra operators}
writeln(12+4);
writeln(12-4);
writeln(12*4);
writeln(12/4);
writeln(12 div 4);
writeln(12 mod 4);
readln;
end.

1
05. 06.
program camparisons(input, output); program logic(input, output);
uses crt; uses crt;
begin begin
clrscr; clrscr;
{ comparison operators } { logical operators }
writeln(6>5); writeln((4<2)and (5>4));
writeln(6<5); writeln((4<2) or (5>4));
writeln(25>=5*5); writeln(not(6<5));
writeln(4+3<=2+6); writeln(not(4=4));
writeln(4=5); writeln(5+2*4 mod 3);
writeln(5<=5); readln;
writeln(5<>5); end.
readln;
end.

07.
program operator_precedence(input, input);
uses crt;
begin
clrscr;
writeln(5+12 mod 5);
writeln(6+3*4-2);
writeln(8*5 div 3 mod 10);
writeln(not (7>=15 mod 10));
writeln(TRUE and not(FALSE));
writeln(not(TRUE) or FALSE);
readln;
end.

2
08.
program Hello;
uses crt;
var s:string;
i:integer;
r:real;
b:boolean;
c:char;
begin
clrscr;
s:='Welcome';
i:=54;
r:=54.6;
b:=true;
c:='v';
writeln('string value is ',s);
writeln('integer value is ',i);
writeln('real value is ',r);
writeln('boolean value is ',b);
writeln('char value is ',c);
readln;
end.

09.
program Findavg(input, output);
uses crt;
var
n1,n2: integer;
avg: real;
begin
clrscr;
writeln('Find the average of two integer numbers');
writeln('--------------------');
write('Enter the first number');
readln(n1);
write('Enter the second number');
readln(n2);
avg:=(n1+n2)/2;
writeln;
writeln('The average is ',avg:3:1);
readln;
end.

3
10.
program largenumber(input,output);
uses crt;
var num:integer;
begin
clrscr;
write('Enter an Integer number: ');
readln(num);
if num>100 then
writeln('It is a large number');
writeln('you have entered ',num);
readln;
end.

11.
program test_ifelse(input, output);
uses crt;
var num, r: integer;
begin
clrscr;
write('Enter a positive integer number');
readln(num);
r:=num mod 2;
if r=1 then
writeln('The number is odd')
else
writeln('The number is even');
readln;
end.

12.
program passfail(input, output);
uses crt;
var m: integer;
begin
clrscr;
write('Enter marks: ');
readln('m');
if (m >= 40) then
writeln('Pass')
else
begin
writeln('Fail');
writeln('Try again');
end;
writeln('Bye');
readln;
end.

4
13.
program whiledo(input, output);
uses crt;
var c: integer;
begin
clrscr;
c := 1;
while c < 10 do
begin
writeln(c);
c := c + 1
end
readln;
end.

14.
program whiledo(input, output);
uses crt;
var x: integer;
begin
clrscr;
x:=5;
while x>0 do
begin
writeln(Information and Communication Technology);
x:=x-1;
end;
readln;
end.

15.
program totalofoddnumbers(input, output);
uses crt;
var x, tot: integer;
begin
clrscr;
x:=1;
tot:=0;
while x<=10 do
begin
tot:=tot+x;
x:=x+2;
end;
writeln('Total of odd numbers from 1 to 10 is: ', tot);
readln;
end.

5
16.
program squarednumbers(input, output);
uses crt;
var n: integer;
begin
clrscr;
n:=1;
while n<=10 do
begin
writeln(n,'^2 = ',n*n);
n:=n+1;
end;
readln;
end.

17.
program repeatuntil(input, output);
uses crt;
var n: integer;
begin
clrscr;
n:=1;
repeat
writeln(n);
n:=n+1
until n=10;
readln;
end.

18.
program add_5numbers(input, output);
uses crt;
var n, x, t: integer;
begin
clrscr;
n:=1;
t:=0;
repeat
write('Enter number: ');
readln(x);
t:=t+x;
n:=n+1;
until n>5;
writeln('Sum = ',t);
readln;
end.

6
19.
program forloop(input, output);
uses crt;
var x: integer;
begin
clrscr;
for x := 1 to 10 do
begin
writeln(x);
end;
readln;
end.

20.
program forloop(input, output);
uses crt;
var x, num, t: integer;
a: real;
begin
clrscr;
for x:=1 to 5 do
begin
writeln('Enter number ',x,':');
readln(num);
t:=t+num;
end;
a:=t/5;
writeln('Average = ',a:5:2);
readln;
end.

21.
program constant(input, output);
uses crt;
var x: integer;
const y=100;
begin
clrscr;
x:=10;
x:=x+y;
writeln(x);
writeln(y);
{y:=y+1;}
readln;
end.

7
22.
program operators(input, output);
uses crt;
begin
clrscr;
writeln(5+5*8/2+2);
writeln((5+5)*8/2+2);
writeln(20/4*5);
writeln(5*10 mod 4);
writeln(5 mod 10*4);
writeln(4+49 mod 9);
writeln(19 div 5*2);
writeln(19*5 div 2);
writeln(16 mod 10/5);
readln;
end.

23.
program xy(input, output);
uses crt;
var x, y: integer;
begin
clrscr;
x := 0;
y := 100;
writeln(x);
writeln(y);
x:=x+10;
writeln(x)
y:=y+x;
writeln(y);
y:=x;
x:=y;
writeln(x);
writeln(y);
readln;
end.

24.
program validation(input, output);
uses crt;
var data: string;
begin
clrscr;
repeat
write('Make your selection A or B: ');
readln(data);
until (data = 'A') or (data = 'a') or (data = 'B') (data = 'b');
writeln('You have selected: ', data);
readln;
end.

8
25.
program squared(input, output);
uses crt;
var x: integer;
begin
clrscr;
repeat
write('Enter an integer between 1 to 100: ');
readln(x);
until (x >= 1) and (x <= 100);
writeln;
writeln('The square of ', x, ' is ', x * x);
readln;
end.

26.
program Grading(input, output);
uses crt;
var m: string;
begin
clrscr;
write('Enter your marks for ICT: ');
readln(m);
if m >= '75' then
writeln('Grade: A')
else if m >= '64' then
writeln('Grade: B')
else if m >= '50' then
writeln('Grade: C')
else if m >= '40' then
writeln('Grade: S')
else
writeln('Grade: F');
readln;
end.

27.
program pro(input, output);
uses crt;
procedure xyz;
begin
writeln('hello');
end;
begin
clrscr;
xyz;
readln;
end.

9
28.
program showname(input, output);
uses crt;
procedure hello1;
var x:integer;
begin
write('enter your name :');
readln(x);
write('hello ',x);
end;
procedure hello2;
var x,y:integer;
begin
write('enter your name :');
readln(x);
write('enter your age :');
readln(y);
write('hello ',x,' age is :',y);
end;
begin
clrscr;
hello1;
writeln;
hello2;
readln;
end.

29.
program showname(input, output);
uses crt;
var x: string;
procedure hello(y: string);
begin
writeln('Hello ', y);
end;
begin
clrscr;
writeln('Enter your name');
readln(x);
hello(x);
readln;
end.

10
30.
program ex(input, output);
uses crt;
var x: integer;
y,z: integer;
r: real;
procedure pro (a: string; b: integer; d: real);
begin
writeln(a,'',b+c,'',r:0:2);
writeln(y);
end;
begin
clrscr;
x:='abc';
y:=5;
z:=10;
r:=7.5;
pro(x, y, z, r);
writeln(z);
readln;
end.

31.
program functiontest(input, output);
uses crt;
var x: integer;
function square(a: integer): integer;
begin
square := a * a;
end;
begin
clrscr;
write('Enter an integer number :');
readln(x);
writeln('Square of ', x, ' is ', square(x));
readln;
end.

11
32.
program functiontest(input, output);
uses crt;
var x,y:integer;
z:real;
function fun1(a,b:integer):real;
begin
fun1:=a/b;
end;
begin
clrscr;
x:=15;
y:=3;
z:=fun1(x,y);
writeln('z',z:6:2);
readln;
end.

33.
program Arraytest(input, output);
uses crt;
var
name: array[1..5] of string;
begin
clrscr;
name[1] := 'Sandaliya';
name[2] := 'Fashions';
name[3] := 'Sri Lanka';
name[4] := 'Australia';
name[5] := 'England';
writeln(name[1]);
readln;
end.

34.
program Arraytest(input, output);
uses crt;
var
name:array[1..5] of string;
x:integer;
begin
clrscr;
name[1]:='John';
name[2]:='Jane';
name[3]:='Jack';
name[4]:='Jill';
name[5]:='Joe';
for x:=1 to 5 do

12
writeln(name[x]);
end.
35.
program Arraytest(input, output);
uses crt;
var
num:array[1..10] of integer;
x,y:integer;
begin
clrscr;
for x:=1 to 10 do
num[x]: = x*x;
for y;=8 downto 2 do
writeln(num[y]);
readln;
end.

36.
program maxnumber(input, output);
uses crt;
var
num:array[1..10] of real;
mx:real;
n,y:integer;
begin
clrscr;
writeln('Enter any ten numbers:');
for n:=1 to 10 do
readln(num[n]);
mx:=num[1];
for n:=2 to 10 do
begin
if num[n]>mx then
mx:=num[y];
end;
writeln('Maximum number is:',mx);
readln;
end.

13
37.
program find_city(input, output);
uses crt;
var
cities:array[101..110] of string;
c:string;
n:integer;
begin
clrscr;
cities[101]:='Kadawatha';
cities[102]:='Colombo';
cities[103]:='Kandy';
cities[104]:='Galle';
cities[105]:='Jaffna';
cities[106]:='Kurunegala';
cities[107]:='Gampaha';
cities[108]:='Hambantota';
cities[109]:='Matara';
cities[110]:='Anuradhapura';
write('Type the city you want to find :');
readln(c);
for n:=101 to 110 do
if c=cities[n] then
begin
writeln('City found');
end;
readln;
end.

14
38.
program find_city(input, output);
uses crt;
var
cities:array[101..110] of string;
c:string;
n,m:integer;
found:boolean;
begin
found = false;
clrscr;
cities[101] = 'Kelaniya';
cities[102] = 'Kandy';
cities[103] = 'Colombo';
cities[104] = 'Galle';
cities[105] = 'Jaffna';
cities[106] = 'Trincomalee';
cities[107] = 'Kurunegala';
cities[108] = 'Polonnaruwa';
cities[109] = 'Badulla';
cities[110] = 'Hambantota';
write('Type the city of the branch you want to find: ');
readln(c);

for n:=101 to 110 do


if c=cities[n] then
begin
found = true;
m:=n;
end;
if found = true then
begin
writeln('Branch found');
writeln('The Branch number is',m);
end
else
writeln('Branch not found in',c);
readln;
end.

15

You might also like