Pascal Paper
Pascal Paper
Suggested answer
Program calculations;
Var num, ans: integer;
Begin
Writeln(‘enter a number’);
Readln(num);
If num>10 then
ans:= num+5
else
ans:= num*3;
writeln(‘the answer is’);
write(ans);
End.
Question 2
The following shows parts of a computer program. Suppose Part A shows the
program before translation and Part B shows the program after translation.
Part A Part B
Readln(num1); 10010011011
Readln(num2); 11110011101
Sum := num1+num2; 11011010110
Writeln(sum); 11011001110
Question 3
Write a program in Pascal that will prompt the user to enter three unequal numbers
and display the smallest among them.
Suggested answer
program smallest;
uses crt;
var num1, num2, num3, smallest :integer;
begin
clrscr;
writeln(‘enter first number’);
read(num1);
writeln(‘enter second number’);
read(num2);
writeln(‘enter third number’);
read(num3);
if num1<num2 then
smallest := num1
else
smallest := num2;
if num3<smallest then
smallest:= num3;
writeln(‘the smallest number is’);
write(smallest);
end.
Question 4
Write a program in Pascal that will print the even numbers between 100 and 300.
Suggested answer
program even_numbers;
uses crt;
var i: integer;
begin
clrscr;
for i := 100 to 300 do
begin
if i DIV 2=0 then
writeln(i);
end;
end.
Question 9
Write a program in Pascal that will accept a number and display the multiplication
table of
that number up to 20 times in the following format :
1x5=5
2 x 5 = 10
3 x 5 = 15
……
……
……
……
……
……
……
20 x 5 = 100
Suggested answer
program multiplication_table;
uses crt;
var i, prod, num: integer
begin
clrscr;
writeln(‘enter number for multiplication table required’);
readln(num);
for i:= 1 to 20 do
begin
prod = i * num;
writeln( i, ‘x’, num, ‘=’, prod);
end;
end.
Question 10
Write a program in Pascal that will accept 30 marks of students and display the
number of students who scored 80 or more, 60 -79 and below 60.
Suggested answer
program grade_count;
uses crt;
var score,a_count,b_count,c_count;
begin
a_count:= 0
b_count:= 0
c_count:= 0
writeln(‘enter score’);
readln(score);
while score< > -1 do
begin
if score>=80 then
a_count:= a_count+1;
if score>=60 and score <80 then
b_count:= b_count+1;
if score <60 then
c_count := c_count+1;
writeln(‘enter score’);
readln(score);
end.
writeln(“number of students who scored 80 or more is );
write(a_count);
writeln(“number of students who scored between 60-79 is );
write(b_count);
writeln(“number of students who scored below 60 is );
write(c_count);
end.