Computer Algorithms and Programming Basics
Computer Algorithms and Programming Basics
Grade :11
Lesson : Writing programs to solve problems- Unit 01
Problem analysis
Building an algorithm for the Problem
Develop a computer program and correcting errors.
Executing a computer program
Use this QR code or this link to learn more about this lesson
through videos.
Problem analysis [Link]
In analyzing the problem, Considers
inputs
processes
outputs
Algorithm
Begin
Input Age
If Age>= 18 then
Display “Adult”
else
Display “Child”
end if
end
connector
Start/Stop
Input/output Process
Decision
Data Flow
When two numbers are given, add them and show the answer
Let us take the first number as X, the second number as Y, the answer as TOTAL.
Array
The array is used to store values in memory using the same name for data belonging to the
same data type.
Features of an Array -
Length - 10 (0 to 9)
marks[0]
marks[1]
marks[2]
marks[3]
marks[4]
marks[5]
marks[6]
marks[7]
marks[8]
marks[9]
45 20 10 50 78 89 55 98 65 32
Name of array marks
Display values in an array.
In pascal output In pseudocode output
write(marks[0]); 45 Display(marks[0]) 45
write(marks[1]); 20 Display(marks[1]) 20
write(marks[2]); 10 Display(marks[2]) 10
write(marks[3]); 50 Display(marks[3]) 50
write(marks[4]); 78 Display(marks[4]) 78
write(marks[5]); 89 Display(marks[5]) 89
write(marks[6]); 55 Display(marks[6]) 55
write(marks[7]); 98 Display(marks[7]) 98
write(marks[8]); 65 Display(marks[8]) 65
write(marks[9]); 32 Display(marks[9]) 32
marks[7]
marks[0]
marks[1]
marks[2]
marks[3]
marks[5]
marks[6]
marks[8]
marks[9]
marks[0]:=500; marks[0]=500
marks[1]:=300; marks[1]=300
300 300 800 600 78 89 55 98 65 32
marks[2]:=800; marks[2]=800
marks
marks[3]:=600; marks[3]=600
marks[0]
marks[1]
marks[2]
marks[3]
marks[4]
marks[5]
marks[6]
marks[7]
marks[8]
marks[9]
marks[6]:= marks[7]+ marks[8]
marks[6]:= 98 + 65
marks[7]:= marks[6]+ marks[5]
marks[7]:= 163 + 89 300 300 800 600 78 89 55 98 65 32
marks[5]:= marks[3]+ marks[0] 300 300 800 600 78 89 163 98 65 32
marks[5]:= 600 + 300
300 300 800 600 78 89 163 252 65 32
300 300 800 600 78 900 163 252 65 32
Model questions
(01). When analyzing a problem, it is important to identify,
1. Input
2. Inputs and outputs
3. outputs
4. Inputs, outputs and processes
(09).Which of the following answers includes the correct variable names that can be used
in a Pascal program?
(10). Consider the pseudo-code below, which includes the label A, to obtain a sum of 10
digits.
Begin
total = 0
count = 1
Repeat
Input number
total = total + number
count = count + 1
………A…………
Display total
End.
What is the correct expression for label A?
1. until count =11
2. until count = 10
3. while count = 11
4. while count = 10
(12) Which of the following answers shows the values of variables A and B, respectively,
when the following statements are executed in a Pascal program?
A:= 9 MOD 10 ;
B:= 10 DIV 1 ;
1. 10,10
2. 9,1
3. 9, 10
4. 1,1
1. 7
2. 10
3. 8
4. 5
X=0
(15). What is the output from this flow chart?
1. Consecutive numbers from 1 to 10
X=X+1
2. Consecutive numbers from 1 to 9 Display X
1. 4. 2. 5. 3. 6. 4. 0.
(21). There are two types of sub - programs . A sub - program which returns an output back
to the main program and a sub – program which does not return an output back to
the main program. The above sub-programs are called respectively is……
(32). What is the answer given in evaluating the expression 13-2 * 5 + 4 ^ 3 in the
computer program?
1. 119 3. 15
2. 67 4. 136
(33). What is the value that Display X outputs in the given pseudo code?
Begin
X=1
While X <10
X=X+1
End while
Display X
End
1. 10 2. 11
3. 9 4. 1
(34). What is the value that Display Z outputs in the given pseudo code?
Begin
a=1
b=1
While a = b
a=a+1
b=b+2
Z=a+b
End while
Display Z
End
1. 2 2. 5
3. 3 4. 4
36). If n is an integer variable, how many times does the following code work?
n=8
m=4
Do while m > 3
n=n-1
Loop
1. execute 3 times.
2. execute 2 times.
3. It never ends.
4. execute one time.
(37) .If n is an integer variable, how many times does the following code work?
n=6
m=2
Do while n > 4
n = n -1
Loop
1. execute 3 times. 2. execute 2 times.
3. It never ends. 4. execute one time.
(38). If m is an integer variable, how many times does the following code work?
m=4
Do while m > 5
m=m-1
Loop
1. execute 2 times. 2. It never starts.
3. It never ends. 4. execute one time.
(39) Which of the following answers does the logical structure of the pseudo-code
above indicate?
1. A sequence
2. A simple choice
3. A Sequence and a repetition
4. A simple choice
Department of Education - Western Province - Development Division 12
(40). What are the answers given by evaluating the following two expressions?
2 ^ 3 + 2> 4 * 3 and 6/2 + 5 <5 * 3 - 2 Start
1. False, true
2. False, false
3. True, false C=0
4. True, True
N
(41) what is the output of this flowchart? C> C=C+
1
Y
1. 4
2. 3 Print C
3. 2
4. 0
(42) If m is an integer variable, how many times does the following
Stop code work?
m=0
Do while m <5
m=m-1
Loop
1. execute 4 times. 2. . execute 5 times..
3. execute 6 times.. 4. execute one time.
Begin
a=5 Start
b=50
Do While a<=b
a=b/a M=30
End while
Display a
End
Y
1. 10 IF
2. 5 M=M+100
M<50
3. 1
4. 50
N
(44) Consider the flow chart below. What is the final
value of M? M=M/5
1. 30
2. 6
End
3. 130
4. 35
A. Sequence
B. Selection
C. Repetition
1. A only
2. A and C only
3. B and C only
4. A and B only
Select the correct order of outputs of above expressions from the given answers.
1. True, False, False
2. True, False, True
3. True, True, False
4. True, True, True
PART 2
(01).
i) The pseudo code written to get the sum of all the even numbers from 1 to 20 is given
below. Fill in the blanks. (5 points).
..............
Sum=0;
N=2;
For ............. = 2 to .............
Sum = .................+N
N = ................+2
Next N
Print ..........................
End.
(02).
(a). When given three numbers, a pseudo-code is given to find the largest number. Fill in the
blanks in this pseudo code.
Begin
Input x,y,z
If (x>y) and (x>z) then
print ……A………
else
(03) .If given three numbers, consider the flow chart given to find the smallest number.
Fill in the blanks here.
Begin
total=0
Input “Enter No. of Student” = N
Avg = 0
For Counter = 1 to ……A……
W=0
Input “student weight” as …….B…..
total= ……..C…… + w
Next counter
avg = total/…..D……
Print “Average weight of students”, …….E…….
End.
Where total is the sum of the weights, N is the number of students and avg is the average
value of the students' weight.
(05) .Write the answers using the flow chart below.
Print x
X=X-10
X>50
stop
(b). Draw a flow chart that matches the pseudo code below.
Begin
Input X,Y
If X > Y then
MAX=X
Else
MAX=Y
End if
Print MAX
End
(07).
(a). Consider the following marks array. Five students' ICT marks were included and an
algorithm was written to read and print them. Name A, B, C, D here.
0 1 2 3 4
13 22 56 78 54
marks
BEGIN
x=0
while x<=….A….
M=marks*….B….]
Display ….D….
….C….=x+1
end while
END
0 1 2 3 4
100 300 500 400 800
P
Prepared by
Chanaka Konthasinghe
ISA - Education Zone, Gampaha
Translated by
Shyamali Ranasinghe
ICT Teacher, Ovitigama Boodiraja M.V. , Pugoda
Use this QR code or this link to learn more about this lesson through videos.
[Link]