Question 1
Consider the following pascal programme
program repetition(input, output);
var x: integer;
begin
x:=1;
repeat
write(x);
x:=x+1;
until x=3;
end.
What is the correct output when the above program is executed ?
Answer
until x reach 3 the repetition will work. The write statement which is above the increment statement when x gets value 1 and 2 display it, when x gets 3 condition becomes true and repetition end.
(write statement in Pascal display the output horizontally)
The output of the program will be
1 2
Question 2
Consider the following pseudocode with label ® to calculate the sum of numbers from 1 to 100.
sum=0
num=0
repeat
num=num+1
sum=sum+num
until ®
for the above mentioned pseudocode, what is the correct condition that matches with the label ®?
Answer
The condition given should be false to work repeat until repetition. Sum is happening after increased the variable num by 1. Finally when the variable num gets 100, the value 100 should add to sum and repetition should break.
so the answer is
num=100
Question 3
Consider the following pascal programme.
var
count:integer;
begin
repeat
count:=0;
write('Hellow ');
count:=count+1;
until count >4;
while count > 4 do
begin
write('Hellow ');
count:=count -1;
end;
readln;
end.
What is the correct output when the above program is executed ?
Answer
Question 4
Consider the following program segment in pascal and write the output of the below program.
program myarr;
var
num:array[0..4] of integer;
i:integer;
begin
num[0]:=15;
num[2]:=18;
num[4]:= 50;
num[1]:=num[4]+10;
num[3]:=num[0]+num[2];
for i:=1 to 4 do
writeln(num[i]);
readln;
end.
Answer
60
18
33
50
Consider the following pascal programme
program repetition(input, output);
var x: integer;
begin
x:=1;
repeat
write(x);
x:=x+1;
until x=3;
end.
What is the correct output when the above program is executed ?
Answer
until x reach 3 the repetition will work. The write statement which is above the increment statement when x gets value 1 and 2 display it, when x gets 3 condition becomes true and repetition end.
(write statement in Pascal display the output horizontally)
The output of the program will be
1 2
Question 2
Consider the following pseudocode with label ® to calculate the sum of numbers from 1 to 100.
sum=0
num=0
repeat
num=num+1
sum=sum+num
until ®
for the above mentioned pseudocode, what is the correct condition that matches with the label ®?
Answer
The condition given should be false to work repeat until repetition. Sum is happening after increased the variable num by 1. Finally when the variable num gets 100, the value 100 should add to sum and repetition should break.
so the answer is
num=100
Question 3
Consider the following pascal programme.
var
count:integer;
begin
repeat
count:=0;
write('Hellow ');
count:=count+1;
until count >4;
while count > 4 do
begin
write('Hellow ');
count:=count -1;
end;
readln;
end.
What is the correct output when the above program is executed ?
Answer
Count value start from 0.
Until condition is count >0.
Write command is above the increment statement of count variable.
The write statement is which is within the repetition, output 'Helow' will appear when count 0,1,2,3,4.
Once count get five break the repetition.
Once count get five break the repetition.
Now count is 5.
It check the while condition count > 4, the result true so it write the output 'Hellow' and then decrease the count by 1.
Now count 4 then while condition get false.
So repeat until loop print hellow 5 times and while loop print hellow 1 time. total times is 6.
->6 times
Question 4
Consider the following program segment in pascal and write the output of the below program.
program myarr;
var
num:array[0..4] of integer;
i:integer;
begin
num[0]:=15;
num[2]:=18;
num[4]:= 50;
num[1]:=num[4]+10;
num[3]:=num[0]+num[2];
for i:=1 to 4 do
writeln(num[i]);
readln;
end.
Answer
60
18
33
50
Explanation
can you explain question 4
ReplyDeletegiven below the answer
DeleteTHIS QUESTIONS REALLY HELPED ME A LOT TO MAKE MY PAPER A SUCCESS , THANK YOU
ReplyDelete