Last Updated:

Pascal Programming Language - Example Codes [3]

Linear algorithms - Pascal Programming Language

 

Calculate the sum and difference of two integers entered by the user from the keyboard.

Decision:

1
2
3
4
5
6
7
8
9
10
11
12
program line_1;
uses crt;
var
a, b: integer;
begin
clrscr;
write(‘a=’)read(a);
write(‘b=’)readln(b);
writeln(a,‘-‘,b, ‘=’, ab);
write(a,‘+’,b, ‘=’, a+b);
readkey;
end.

Find the arithmetic mean of three real numbers set from the keyboard.

Decision:

1
2
3
4
5
6
7
8
9
10
11
12
13
program line_2;
uses crt;
var
a, b, c: real;
begin
clrscr;
write(‘a=’)read(a);
write(‘b=’)read(b);
write(‘c=’)readln(c);
write('The arithmetic mean of a, b, and c = ');
write(((a+b+c)/3):4:2);
readkey;
end.

The cathets of a right triangle are given. Find its area and hypotenuse.

Decision:

1
2
3
4
5
6
7
8
9
10
11
12
13
program line_3;
uses crt;
var
a, b: real;
begin
clrscr;
writeln('Enter right triangle cathetes');
write(‘a=’)read(a);
write(‘b=’)read(b);
writeln('Hypotenuse = ', sqrt(sqr(a)+sqr(b)))));
write('Area = ', a*b/2);
readkey;
end.

The user enters from the keyboard a value expressed in kilobytes. The program translates it into bits and megabytes.

Decision:

1
2
3
4
5
6
7
8
9
10
11
12
13
program line_4;
uses crt;
var
kb, b: longint;
mb: real;
begin
clrscr;
write('kb (kilobyte) = ')readln(kb);
b:=kb*1024*8;
mb:=kb/1024;
writeln(kb,' kilobyte = ', b, ' bit = ', mb:6:4, 'mb');
readkey;
end.

Three resistances R1, R2 and R3 are connected in parallel. Find the resistance of the R0 connection.

Decision: