100% found this document useful (2 votes)
1K views

Pascal Paper

The document contains 10 questions about writing programs in Pascal. Each question provides an algorithm and the suggested Pascal code to implement the algorithm. The questions cover topics such as accepting user input, performing calculations, conditional statements, loops, and counting values within ranges.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
1K views

Pascal Paper

The document contains 10 questions about writing programs in Pascal. Each question provides an algorithm and the suggested Pascal code to implement the algorithm. The questions cover topics such as accepting user input, performing calculations, conditional statements, loops, and counting values within ranges.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Question 1

Write a program in Pascal using the following algorithm:

a. Prompt the user to enter a number.


b. Accept the value and store it in variable num.
c. Check to see if num is more than 10. If it is more than 10 add 5 to it. Otherwise
multiply num by 3. Store the results in a variable Ans.
d. Display the results in Ans along with the message “the answer is”.

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

a. Which generation or level language is Part A?


b. Which generation or level language is Part B?
c. Name one translator that can be used to convert Part A to Part B.
d. What is the generic name for the program code in Part A before translation?
e. What is the generic name of the program code in Part B after translation?
Suggested answer
a. High-level or 3rd generation language
b. Machine-level or 1st generation language
c. Compiler
d. Source code
e. Object code

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.

You might also like