Computer Science: Looping & Branching

BY IN IB Computer Science Comments Off on Computer Science: Looping & Branching

Read the instructions carefully!

1. Construct a program that can have an output like this:
(Notes: you have to use at least one looping)
1 2 4 8 16

2. Predict the output of the following Pascal program:
(Notes: do not use the computer for this question)
uses crt;
var
i,j,k:integer;
begin
for i:=1 to 5 do
begin
j:=1;
k:=2;
while (j<=5) do
begin
writeln(i);
j:=j+k;
k:=k+1;
end;
end;
end.

3. Construct a program that can have an output like this:
2 4 6 8 6 4 2
(Notes: try to use only one looping, combined with branching)

4. Construct a program that have an input number 1, 2 or 3 and give an output like this:
Input: 1
Output: You entered 1
Input: 2
Output: You entered 2
Input: 3
Output: You entered 3
plus, program can display an error message if user input any values other than 1, 2 or 3
Input: 5
Output: Please enter only 1, 2 or 3




Comments are closed.