0% found this document useful (0 votes)
13 views355 pages

Programing Notes

The document outlines the basics of programming for Grade 11 ICT, focusing on problem-solving steps, including analyzing problems, creating algorithms, developing programs, and testing/debugging. It provides examples of problems such as adding two numbers, calculating averages, and finding areas and circumferences of geometric shapes, along with their respective inputs, processes, and outputs. Additionally, it introduces algorithms, control structures, and flowcharts as tools for programming.

Uploaded by

harshakumara.ict
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views355 pages

Programing Notes

The document outlines the basics of programming for Grade 11 ICT, focusing on problem-solving steps, including analyzing problems, creating algorithms, developing programs, and testing/debugging. It provides examples of problems such as adding two numbers, calculating averages, and finding areas and circumferences of geometric shapes, along with their respective inputs, processes, and outputs. Additionally, it introduces algorithms, control structures, and flowcharts as tools for programming.

Uploaded by

harshakumara.ict
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Grade 11 ICT Unit 01 Programming

INFORMATION AND COMMUNICATION


TECHNOLOGY

Grade 11
Grade 11 ICT Unit 01 Programming

1st Lesson
Problem solving with Computer
Programs
.eg¨ úi£ug l%uf,aL ,sùu
Grade 11 ICT Unit 01 Programming

Four Steps of Problem solving


.eg¨ úi£fï mshjr 4 කි
[Link] the Problem 1 .eg¨j úYaf,aIkh lsÍu
2 .eg¨ úi£u i|yd
[Link] an Algorithm for
we,af.dß;u [Link]
the Problem
3 l%uf,ALkh
[Link] Programs. 4 mÍlaId lsÍu iy fodaI
[Link] and debugging. bj;A lsÍu
Grade 11 ICT Unit 01 Programming

1. Analyzing the Problem


.eg¨j úYaf,aIKh lsÍu
Identify the input, Process and Output of the Problem
.eg¨jla úYaf,aIKh lsÍfï § tys wdodk" l%shdj,sh yd m%;sodk
fjka fjka j y÷kd .kS
Grade 11 ICT Unit 01 Programming

Inputs/wdodk
Process/ Output /
l%shdj,sh m%;sodk
Grade 11 ICT Unit 01 Programming

Problem -01 Add two numbers and display the Total.


.eg¨j 01 ( ixLHd foll tl;=j fiùu
Input : Two numbers (n1,n2)
Process : Calculate the total(total=n1+n2)
Output : Total

wdodk ( ixLHd fol (n1,n2)


l%shdj,sh ( ixLHd fol tl;= lsÍu(tl;=j=n1+n2)
m%;sodkh ( tl;=j
Grade 11 ICT Unit 01 Programming

Problem -02
Calculate the average marks of Three
subjects.

.eg¨j 02 (
úIhka 3l ,l=Kq we;=<;a l< úg idudkH
,l=Kq .Kkh lsÍu
Grade 11 ICT Unit 01 Programming

Answer
Input : Marks of three subjects (m1,m2,m3)
Process : Average Marks=(m1+m2+m3)/3
Output : Average Marks

wdodk (úIhka 3 ys ,l=Kq (m1,m2,m3)


l%shdj,sh (idudkH ,l=Kq =(m1+m2+m3)/3
m%;sodkh (idudkH ,l=Kq
Grade 11 ICT Unit 01 Programming

Problem 03 - Calculate area of the


rectangle according to the given length
and width.
Width(w)

.eg¨j 03 ( Length(l)

iDcqfldaKdi%hl È. m<, ,nd ÿka úg tys


j¾.M,h .Kkh lsÍu
Grade 11 ICT Unit 01 Programming

Answer
Input : Length (l) and width(w) of the Rectangle
Process : Area= length x width
Output : Area

wdodk (iDcqfldaKdi%hl È. iy m<,


l%shdj,sh (j¾.M,h = È. x m<,
m%;sodkh (j¾.M,h
Grade 11 ICT Unit 01 Programming

Problem 04 - Calculate perimeter of


the rectangle according to the given
length and width. Length(l)

Width(w)
.eg¨j 04 (
iDcqfldaKdi%hl È. m<, ,nd ÿka úg tys
mßñ;sh .Kkh lsÍu
Grade 11 ICT Unit 01 Programming

Problem 05 -Calculate circumference of


the circle according to the given radius(r).
Radius(r)
.eg¨j 05 (
wrh (r) ,nd ÿka úg jD;a;hl
mßêh fiùu
Grade 11 ICT Unit 01 Programming

Answer
Input : Radius(r) of the Circle Radius(r)
Process : pi (𝝅) =22/7
Circumference = 𝟐𝝅𝒓
Output : Circumference

wdodk (jD;a;hl wrh (r)


l%shdj,sh (pi (𝝅) =22/7
mßêh =𝟐𝝅𝒓
m%;sodkh (mßêh
Grade 11 ICT Unit 01 Programming

Problem 06- Calculate area and


circumference of the circle according to
the given radius(r).
.eg¨j 06 ( Radius(r)

wrh (r) ,nd ÿka úg jD;a;hl


j¾.M,h iy mßêh fiùu
Grade 11 ICT Unit 01 Programming

Input : Radius(r) of the Circle Radius(r)


Process : pi (𝝅) =22/7
Area = 𝝅𝒓𝟐
circumference= 2𝝅r
Output : Area
wdodk (jD;a;hl wrh (r)
l%shdj,sh (pi (𝝅) =22/7
j¾.M,h = 𝝅𝒓𝟐
mßêh = 2𝝅r
m%;sodkh (j¾.M,h iy mßêh
Grade 11 ICT Unit 01 Programming

Problem 07-Calculate area of the square.


iup;=ri%hl j¾.M,h .Kkh lsÍu
Input : length of a side(l)
Process : area=l x l
Output : area

wdodk (iup;=ri%hl me;a;l È. length of a side(l)


l%shdj,sh (j¾.M,h = È. x È.
m%;sodkh (j¾.M,h
Grade 11 ICT Unit 01 Programming
Grade 11 ICT Unit 01 Programming

2011-Part II-Q1-(ii)
• G.C.E (Ordinary Level) candidates can obtain their
examination results from the website of the
Department of Examinations.
• When the Index Number is entered to the data entry
form of the web site, the system validates it.
• If it is valid, then the results will be retrieved from the
database and displayed on the screen.
• Write the input , process and output for this scenario
Grade 11 ICT Unit 01 Programming

2011-Part II-Q1-(ii)
• w'fmd'i' ^idudkH fm<& whÿïlrejkag ;u úNd. m%;sM,
úNd. fomd¾;fïka;=fjys fjí wvúfhka (website) ,nd .;
yelsh.
• fjí wvúfhys o;a; msúiqï fmdaruhg úNd. wxlh we;=<;a
l< úg moaO;sh uÕska tys j,x.=;djh (validity) msßlaihs.
• th j,x.=jkafka kï o;a; iuqodfhka m%;sM, ,ndf.k, th
;srfhys m%o¾YKh flf¾. by; ixisoaêfhys wdodkh (input)
l%shdj,sh (process) iy m%;sodkh (output) ,shd olajkak.
Grade 11 ICT Unit 01 Programming

2010-part II- Q1-(iii)


• Imagine that you have purchased a few items from a shop.
The cashier has issued the bill. you have found that the
amount mentioned in the bill is incorrect and you have
informed the cashier. By considering yourself as a system.
identify the input, process, and the output in the above
scenario.
Tn idmamqjlska NdKav lsysmhla ñ,oS f.k we;ehs is;kak. whleñ úiska ì,a
m; ksl=;a lr we;. ì,a mf;ys oelafjk uqo, jerÈ nj Tn wkdjrKh lr
f.k, ta nj whleñhd fj; okajd we;.
Tn moaO;shla (system) hehs Wml,amkh lr, fuu isÿùfï oS wdodkh (input),
l%shd ms<sfj< (process) iy m%;sodkh (output) yÿkd .kak.
Grade 11 ICT Unit 01 Programming
Grade 11 ICT Unit 01 Programming

Input : Incorrect Bill and selected Items


Processes : 1) compare the no. of items with the bill
2) compare the unit cost with the bill
3) calculate the total
Output : Inform the cashier

wdodk ( ì,a m; iy f;dard .;a NdKav


l%shdj,sh ( ñ,oS .;a NdKav tall .Kk ì,am; iuÕ ixikaOkh
tall ñ, ixikaOkh
uq¿ uqo, fiùu
m%;sodkh (ta nj whleñhdg oekqï oSu
Grade 11 – ICT Unit 9 Programming

Four Steps of Problem solving


.eg¨ úi£fï mshjr 4 ls'
1. Analyzing the Problem 1' .eg¨j úYaf,aIKh lsÍu
2' .eg¨ úi£u i|yd
2. Creating an Algorithm
for the Problem we,af.dß;u [Link]
3'l%uf,ALkh
3. Developing Programs. 4'mÍlaId lsÍu iy fodaI
4. Testing and debugging. bj;A lsÍu
Grade 11 – ICT Unit 9 Programming

2. Creating an Algorithm for the


Problem

.eg¨ úi£u i|yd


we,af.dß;u [Link] [Link]
Grade 11 – ICT Unit 9 Programming

What is an Algorithm?

we,af.dß;uhla hkq l=ulao ?


Grade 11 – ICT Unit 9 Programming

An algorithm is a step-by-step
procedure for solving a problem.

.eg¨jla úi£u i|yd [Link] lrkq


,nk mshjr oelaùfï l%uh
we,af.dß;uhla f,i ye¢ka fõ'
Grade 11 – ICT Unit 9 Programming

There are two types of Algorithm


1. Graphical representation Flow chart
rEmuh wdldrh  .e,Sï igyka

2. Textual representation Pseudo codes


,sÅ; wdldrh jHdc flA;
Grade 11 – ICT Unit 9 Programming
Start
.e,Sï igyka
Flow chart Input Tea leaves,
hot water, sugar

Put tea powder to mug


and pour hot water

Add some sugar and strain

A cup of tea

Stop
Grade 11 – ICT Unit 9 Programming

.e,Sï igyka

Process Input / Output


Start /stop

A
Decision connector Flow lines
Grade 11 – ICT Unit 9 Programming

Control Structures
md,k jHqy
wkql%uh (Sequence)
jrKh (Selection)
mqk¾lrKh (Iteration)
Grade 11 – ICT Unit 9 Programming

1' wkql%uh (Sequence)


•we,af.dß;uhl msysá mshjr lsysmhla fyda
ish,a, u fyda wdrïNl mshjrl isg
wjidk mshjr olajd by< isg my<g
tfl,aaf,a wkqqms<sfj<ska ls%hd;Aul ùu
•If the steps from the beginning to the end of
an algorithm are carried out in a strict order,
it is called a sequence.
Grade 11 – ICT Unit 9 Programming

WodyrK mäfm<ska .uka lsÍfï § mäfhka


mäh [Link] fyda neiSu
Climbing up or down step by step
when going on a staircase
Grade 11 – ICT Unit 9 Programming

Problem 01 :
Add two numbers and display the
total
.eg¨j 01 (
ixLHd foll tl;=j fiùu
Grade 11 – ICT Unit 9 Programming

Start
.e,Sï igyk
INPUT TWO
Flow chart NUMBERS(N1,N2)

TOTAL=N1+N2

DISPLAY TOTAL

Stop
Grade 11 – ICT Unit 9 Programming
wdrïNh

.e,Sï igyk ixLHd fol (n1,n2)


Flow chart wdodkh

ixLHd fol tl;=


lsÍu(tl;=j=n1+n2)

tl;=j m%;sodkh

wjidkh
Grade 11 – ICT Unit 9 Programming

PSEUDO CODE jHdc flA;


BEGIN wdrïNh
Input two Numbers(n1,n2) ixLHd fol (n1,n2) wdodkh
Total= n1+n2 tl;=j=n1+n2
Display Total tl;=j m%;sodkh
END wjidkh
Grade 11 - ICT Unit 1 Programming 02

Problem 02 :
Calculate the average marks of
Three subjects.
.eg¨j 02 (
úIhhka 3l ,l=Kq we;=<;a l<
úg idudkH ,l=Kq .Kkh lsÍu'
Grade 11 – ICT Unit 9 Programming

Start
PSEUDO CODE
Input Three Subject BEGIN
Marks
(m1,m2,m3) Input Three Subject
Marks (m1,m2,m3)
Average = (m1+m2+m3)/3
Average = (m1+m2+m3)/3
Display Average
END
Display Average

Stop
Grade 11 – ICT Unit 9 Programming
wdrïNh
jHdc flA;
úIhhka 3 ys ,l=Kq wdrïNh
wdodkh(m1,m2,m3)
úIhhka 3 ys ,l=Kq wdodkh
(m1,m2,m3)
idudkH ,l=Kq = (m1+m2+m3)/3
idudkH ,l=Kq = (m1+m2+m3)/3
idudkH ,l=Kq m%;sodkh
idudkH ,l=Kq
m%;sodkh wjidkh

wjidkh
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

Example 03 :
Calculate Area of a rectangle according to
the given length and width.
.eg¨j 03 (
iDcqfldaKdi%hl È. , m<, ,nd ÿka úg tys
j¾. M,h .Kkh lsÍu'
Grade 11 – ICT Unit 9 Programming

Start
Flow chart
Input length (l)
Width (w) BEGIN
Input length (l) Width (w)
Area = l x W Area = l x W
Display Area
END
Display Area
PSEUDO CODE
Stop
Grade 11 – ICT Unit 9 Programming

wdrïNh .e,Sï igyk


È. (l) m<,(w)
wdodkh wdrïNh
È. (l) m<,(w) wdodkh
j¾. M,h = l x W j¾. M,h = l x W
j¾. M,h m%;sodkh
j¾. M,h m%;sodkh wjidkh
jHdc flA;
wjidkh
Grade 11 – ICT Unit 9 Programming

•Problem 03 :
Calculate Area and perimeter of a rectangle
according to the given length and width.
.eg¨j 03 (
iDcqfldaKdi%hl È. , m<, ,nd ÿka úg tys
j¾.M,h iy mßñ;sh .Kkh lsÍu'
Grade 11 – ICT Unit 9 Programming

Start
Flow chart
Input length (l)
Width (w) BEGIN
Input length (l) Width (w)
Area = l x W Area = l x W
Perimeter=2x(l+w)
Perimeter=2x(l+b)
Display Area & Display Area & Perimeter
Perimeter END
PSEUDO CODE
Stop
Grade 11 – ICT Unit 9 Programming

wdrïNh .e,Sï igyk


È. (l) m<,(w)
wdodkh wdrïNh
È. (l) m<,(w) wdodkh
j¾. M,h = l x W
mßñ;sh = 2x(l + w) j¾. M,h = l x w
mßñ;sh = 2x(l + w)
j¾. M,h m%;sodkh j¾. M,h m%;sodkh
wjidkh
wjidkh jHdc flA;
Grade 11 – ICT Unit 9 Programming

Problem 04:
Calculate area of the square.
length of a side(l)
.eg¨j 04 (
iup;=ri%hl j¾.M,h .Kkh lsÍu
Grade 11 – ICT Unit 9 Programming

Flow chart Start


length of a Side (l)
Input Length of a
Side (l)

BEGIN
Area = l x l
Perimeter=4Xl Input length of a Side (l)
Area = l x l
Display Area & Perimeter=4Xl
Perimeter
Display Area & Perimeter
Stop END
Grade 11 – ICT Unit 9 Programming

Flow chart wdrïNh

iup;=ri%hl me;a;l wdrïNh


È.(l) wdodkh
iup;=ri%hl me;a;l È.(l)
wdodkh
j¾.M,h = È. x È.
j¾.M,h = È. x È.

j¾.M,h j¾.M,h m%;sodkh


m%;sodkh wjidkh

wjidkh
Grade 11 – ICT Unit 9 Programming

Problem 05 :
Calculate circumference & area of the circle
according to the given radius(r).
Radius(r)
.eg¨j 05 (
wrh (r) ,nd ÿka úg jD;a;hl
j¾.M,h mßêh fiùu
A=pi.r.r
C=[Link].r
Grade 11 – ICT Unit 9 Programming

.e,Sï igyk Start

Flow chart Input Radius (r)


BEGIN
Input Radius (r) Pi=22/7
Area=pi x r x r
pi= 22/7
Circumference = 2 x pi x r
Area=pi x r x r
Circumference = 2 x pi x r Display Area &
Display Area & Circumference Circumference
END
Stop
Grade 11 – ICT Unit 9 Programming

PSEUDO CODE
BEGIN
Input Radius (r)
Circumference = 2 x 22/7 x r
Display Circumference
END
Grade 11 – ICT Unit 9 Programming

jHdc flA;
wdrïNh
jD;a;hl wrh (r) wdodkh
mßêh = 2 x 22/7 x r
mßêh m%;sodkh
wjidkh
Grade 11 – ICT Unit 9 Programming

Example 04 :
Calculate circumference & area of a circle
according to the given radius(r).
WodyrK 04 (
wrh (r) ,nd ÿka úg jD;a;hl j¾.M,h
iy mßêh fiùu '
Grade 11 – ICT Unit 9 Programming

Home work 01
• Write a Python
program(algoritms) to input a
temperature in Celsius and
convert it in to the Fahrenheit
temp.

• Fahrenheit = 9/5* Celsius +32


Grade 11 – ICT Unit 9 Programming

.e,Sï igyk Start

Flow chart Input temperature


in celceus (c)
BEGIN
Input temperature in Celsius (c)
Temp in Fahrenheit=9/5xc+32 Temp in fareinght=9/5xc+32

Display Temp in Fahrenheit


END Display temp in
Fahrenheit

Stop
Grade 11 – ICT Unit 9 Programming

Home work 02
• Algorithm and Python code to convert length in mm to
length in inches

25 mm = 1 inch
Grade 11 – ICT Unit 9 Programming

.e,Sï igyk Start

Flow chart Input length in mm


(l_mm)
BEGIN
Input length in mm (l_mm)
L_inch=l_mm/25 L_inch=l_mm/25

Display length in inches(l_inch)


END
Display l_inch

Stop
Grade 11 – ICT Unit 9 Programming

What is the maximum Number?

18 10

Maximum
Number
Grade 11 – ICT Unit 9 Programming

2. Selection
Selection is a situation where step(s)
are executed depending on whether
a condition of an algorithm is
satisfied or not.
Grade 11 – ICT Unit 9 Programming

2 jrKh
we,af.dß;uhl we;=<;a fldkafoaishla
;Dma; ùu fyda fkdùu fyda wkqj l%shd;aul
l< hq;= mshjr l=ula o hkak ;SrKh jk
wjia:djla jrKhla f,i ye¢kafõ'
Grade 11 – ICT Unit 9 Programming

There are two choices; if the condition is


satisfied, one is selected and if it is not
satisfied, the other is selected.
fuys § jrK folla mj;sk w;r
fldkafoaish ;Dma; jkafka kï tla
jrKhla o ;Dma; fkdjkafka kï wfkla
jrKh o f;dard .efka'
Grade 11 – ICT Unit 9 Programming

Two Types

• Single condition selection


• If ………endif
• If …….else……endif
• Many condition selection
Grade 11 – ICT Unit 9 Programming

If….endif
Begin
In...............
IF N>0 THEN
Display Number(N)
ENDIF
END.
Grade 11 – ICT Unit 9 Programming

If….endif Begin Start


Input Your Age
IF Age>=18 THEN
Display “You can Vote” INPUT Age
ENDIF
END.

DISPLAY “You yes


can vote” Age >=18
no

Stop
Grade 11 – ICT Unit 9 Programming

Start
If ….ELSE...endif
INPUT Age

DISPLAY yes
“ADULT” Age >=18
no
DISPLAY
“CHILD”
Stop
Grade 11 – ICT Unit 9 Programming

Problem 01 :
If age is 18 or more than 18 then display
“Adult” otherwise display the result as
“child”
.eg¨j 01 (
jhi 18 g fyda 18 g jeä kï zjeäysáZ
f,i;a tfia fkdue;s kï z<udZ f,i;a
m%o¾Ykh fõ'
Grade 11 – ICT Unit 9 Programming

Start
.e,Sï igyk
Flow chart INPUT Age

DISPLAY yes
“ADULT” Age >=18
no
DISPLAY “CHILD”
Stop
Grade 11 – ICT Unit 9 Programming

wdrïNh

.e,Sï igyk
Flow chart jhi wdodkh

DISPLAY Tõ
“jeäysá” jhi >=18
ke;
DISPLAY “<ud”
Stop
Grade 11 – ICT Unit 9 Programming

Syntax for simple Selection


IF <CONDITION> THEN
<true result>
…………
ELSE
<false result>
…………
END IF
Grade 11 – ICT Unit 9 Programming

PSEUDO CODE
BEGIN
If Age >= 18 THEN
Display “Adult”
ELSE
Display “Child”
END IF
END
Grade 11 – ICT Unit 9 Programming

Start
.e,Sï igyk
Flow chart INPUT Age

DISPLAY yes
“CHILD” Age <18
no
DISPLAY “ADULT”
Stop
Grade 11 – ICT Unit 9 Start
Programming

.e,Sï igyk INPUT a


Numnber(N )
no
Flow chart N =0
yes
DISPLAY “positive yes
number” N >0
no
DISPLAY “Negative
number”
Stop
Grade 11 – ICT Unit 9 Programming

Selection
if (cond) then
Statement A

else
Statement B
… if cond:
endif Statement A

else:
Statement B

GCE (A/L) ICT Training for Teachers
Grade 11 – ICT Unit 9 Programming

PSEUDO CODE
BEGIN
If Age < 18 THEN
Display “Child”
ELSE
Display “Adult”
END IF
END
Grade 11 – ICT Unit 9 Programming

Problem 02 :
At least 40 average marks “pass”
otherwise “fail”.
.eg¨j 02 (
wju jYfhka ,l=Kq 40la we;akï
ziu;aZ f,i o tfia fkdue;skï zwiu;aZ
f,i o m%o¾Ykh ùu'
Grade 11 – ICT Unit 9 Programming

Marks

80
39
40 40
Pass
Fail
pass
Grade 11 – ICT Unit 9 Programming

Start
.e,Sï igyk
Flow chart INPUT
Marks

DISPLAY yes Marks


“PASS”
>=40
no
DISPLAY “FAIL”
Stop
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

Problem 03 :
Finding whether the given number is
“Odd” or “Even”

.eg¨j 03 (
fok ,o ixLHdjla ‘T;af;a’ o
‘brÜfÜ’ o hk nj fiùu'
Grade 11 – ICT Unit 9 Programming

Start
.e,Sï igyk INPUT number(n)
Flow chart R=the remainder of n/2

DISPLAY yes
“Even” R=0

no
DISPLAY “Odd”
Stop
Grade 11 – ICT Unit 9 Programming

PSEUDO CODE
BEGIN
Input a number(n)
R=the remainder of n/2
IF r=0 THEN
display “Even”
ELSE
DISPLAY “odd”
ENDIF
END
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

6
5
10 Remainder

Odd
Even
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

(2) Selection
(Multiple conditions)
jrKh (nyq fldkafoais )
Grade 11 – ICT Unit 9 Programming

What is the Result?


IF marks>= 75  “A”
IF marks>= 65  “B”
IF marks>= 55  “C”
IF marks>= 35  “S”
If marks < 35  “W”
Grade 11 – ICT Unit 9 Programming

What is the Result?


IF MY Marks
50 >35
>65
>75
>55
My result
is “S”
BSAC?? NO
yes
NO
NO
Grade 11 – ICT Unit 9 Programming

What is the Result?


IF MY Marks
30 >55
>75
>35
>65
My result
B
CS ? NO
No
Ais?“W”
NO
Grade 11 – ICT Unit 9 Programming

What is the Result?


IF MY Marks
80 >75
My result
A is?“A”
Yes
Grade 11 – ICT Unit 9 Programming

Selection (Nested IF )
When there are multiple
conditions one after the other,
Nested IF is used.
Grade 11 – ICT Unit 9 Programming

jrKh - nyq fldkafoais


fldkafoaishlg miqj fldkafoaishla
jYfhka fldkafoais iuQyhla fhfok
wjia:djl NESTED IF fhdÞ .efka'
Grade 11 – ICT Unit 9 Programming

Satisfied
Condition 1
Not satisfied
Satisfied
Condition 2

Not satisfied
Grade 11 – ICT Unit 9 Programming

Example 01
Finding the Grade when the marks scored by
a student for a subject is given as input.
IF marks>= 75  “A”
IF marks>= 65  “B”
IF marks>= 55  “C”
IF marks>= 35  “S”
If marks < 35  “W”
Grade 11 – ICT Unit 9 Programming

Wod( 1 -
idudkH ,l=Kq ,nd ÿka úg m%;sM, m%o¾Ykh
lsÍu.
IF ,l=Kq >= 75  “A”
IF ,l=Kq >= 65  “B”
IF ,l=Kq >= 55  “C”
IF ,l=Kq >= 35  “S”
IF ,l=Kq < 35  “W”
Grade 11 – ICT Unit 9 Programming
yes
Start INPUT m >=75 DISPLAY
“A”
Marks(m) No
yes DISPLAY
m >=65 “B”
No
yes DISPLAY
m >=55 “C”

No
yes DISPLAY
m >=35 “S”
No
DISPLAY “W”
Stop
Grade 11 – ICT Unit 9 Programming
yes
Start INPUT m >=75 RESULT=“A”
Marks(m) No
yes
m >=65 RESULT=“B”

No
yes
m >=55 RESULT=“C”

No
yes
m >=35 RESULT=“S”

No
RESULT=“W” DISPLAY
RESULT
Grade 11 – ICT Unit 9 Programming
begin
INPUT MARKS(M)
IF M>=75 THEN
RESULT="A"
ELSE IF M>=65 THEN
RESULT= "B"
ELSE IF M>55 THEN
RESULT= "C"
ELSE IF M>35 THEN
RESULT= "S"
ELSE
RESULT= "W"
ENDIF
ENDIF
ENDIF
ENDIF
DISPLAY RESULT
END.
Grade 11 – ICT Unit 9 Programming

Selection (Nested IF )
jrK md,k jHqyh
IF CONDITION 1 THEN RESULT 1
ELSEIF CONDITION 2 THEN RESULT 2
ELSEIF CONDITION 3 THEN
RESULT 3
….
ELSE
ELSE RESULT
ENDIF
Grade 11 – ICT Unit 9 Programming

Begin ELSE IF m>=35 THEN


Input Your Marks(m) Display “S”
IF m>=75 THEN ELSE
Display “A”
Display “W”
ELSE IF m>=65 THEN
Display “B” END IF
ELSE IF m>=55 THEN END IF
Display “C” END IF
END IF
END.
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

E.g. 2-
Develop the Algorithm to display the
name of the House in the School
according to the Index number(idno).
Wod( 2 -
we;=<;aùfï wxlh ,nd ÿka úg
mdif,a ksjdih m%o¾Ykh
Grade 11 – ICT Unit 9 Programming

R=remainder of idno/4

IF R = 0  “KOKILA”
IF R = 1  “MAYURA”
IF R = 2  “HANSA”
IF R = 3  “LIHINI”
Grade 11 – ICT Unit 9 Programming

IF IDNO
5
6
12 Remainder
fYaIh

House
House BC
Grade 11 – ICT Unit 9 Programming
yes
Start R=0 DISPLAY
“ A”
No
INPUT yes DISPLAY
index R=1 “B”
no(idno)
No
yes DISPLAY
R=the remainder of R=2 “C”

idno/4 No
DISPLAY “D”

Stop
Grade 11 – ICT Unit 9 Programming
yes
wdrïNh R=0 “ A”
No m%;sodkh
we;=<;aùfï yes “ B”
R=1 m%;sodkh
wxlh(idno)
No
wdodkh yes “ C”
R=2 m%;sodkh

R=idno/4 ys fYaIh No
“ D”
m%;sodkh
wjidkh
Grade 11 – ICT Unit 9 Programming

Begin
Input Index No.(idno) ELSE
R = the remainder of Display “DD”
idno/4 END IF
IF R = 0 THEN
Display “AA” END IF
ELSE IF R = 1 THEN END IF
Display “BB” END.
ELSE IF R = 2 THEN
Display “CC”
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

identifiers
Grade 11 – ICT Unit 9 Programming

Develop the Algorithms.


• To find final amount(f_am) according to the given
total amount(t_am) and relevant discount rates.
IF t_am>= 10,000  20%
IF t_am>= 5,000  10%
IF t_am>= 2,000  5%
IF t_am< 2,000  “No discounts”
F_am= t_am - (t_am x 20%)
Grade 11 – ICT Unit 9 Programming

Develop the Algorithms.


• NdKavj, uq¿ uqo,(t_am) ,nd ÿkaúg my; i|yka
jÜgï m%;Ys ; wkqj f.úh hq;= uqo,(F_am) fyda
jÜgula ,nd ke; hk m%ldYh m%o¾Ykh ùu
IF t_am>= 10,000  20%
IF t_am>= 5,000  10%
IF t_am>= 2,000  5%
IF t_am< 2,000  “No discounts”
F_am= t_am - (t_am x 20%)
Grade 11 – ICT Unit 9 Programming

Control Structures
md,k jHqy
 wkql%uh (Sequence)
 jrKh (Selection)
 mqk¾lrKh (Iteration)
Grade 11 – ICT Unit 9 Programming

Selection jrKh

Simple Selection Selection with


ir, jrKh multiple condition
fldkafoais tlla nyq fldkafoais iys;
iys; jrKh jrKh
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

Last week Home Work…


Grade 11 – ICT Unit 9 Programming

Develop the Algorithms.


• To find final amount(f_am) according to the given
total amount(t_am) and relevant discount rates.
IF t_am>= 10,000  20%
IF t_am>= 5,000  10%
IF t_am>= 2,000  5%
IF t_am< 2,000  “No discounts”
F_am= t_am - (t_am x 20%)
Grade 11 – ICT Unit 9 Programming

Develop the Algorithms.


• NdKavj, uq¿ uqo, (t_am) ,nd ÿkaúg my; i|yka
jÜgï m%;sY; wkqj f.úh hq;= uqo, (F_am) fyda
jÜgula ,nd ke; hk m%ldYh m%o¾Ykh ùu
IF t_am>= 10,000  20%
IF t_am>= 5,000  10%
IF t_am>= 2,000  5%
IF t_am< 2,000  “No discounts”

F_am= t_am - (t_am x 20%)


Grade 11 – ICT Unit 9 Programming

Answer
Grade 11 – ICT Unit 9 Programming

Start t_am> yes


10000 F_am= t_am - (t_am x 20%)
INPUT total
amount No
(t_am) t_am> yes
F_am=
5000 t_am - (t_am x 10%)

No

A B
Grade 11 – ICT Unit 9 Programming

A B
Yes
t_am> F_am=
2000 t_am - (t_am x 5%)

No
DISPLAY
DISPLAY
F_am
“No discounts”

Stop
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

BEGIN
input total amount(t_am)
if t_am >10000 then
F_am= t_am - (t_am x 20%)
else if t_am >5000 then
F_am= t_am - (t_am x 10%)
else if t_am >2000 then
F_am= t_am - (t_am x 5%)
else
Display "You haven't any discount“
f_am=t_am
end if
end if
end if
Display (F_am)
end.
Grade 11 – ICT Unit 9 Programming

Control Structures
md,k jHqy
 wkql%uh (Sequence)
 jrKh (Selection)
 mqk¾lrKh
(Iteration/REPETITION)
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

3. Iteration / Repetition
If one or several steps of an
algorithm are repeated until a
condition is satisfied, it is called
repetition.
Grade 11 – ICT Unit 9 Programming

Not satisfied
;Dma; fkdfõ
Condition
fldkafoaish
Satisfied
;Dma; fõ
Grade 11 – ICT Unit 9 Programming

E.g. 1-
Develop the Algorithm to display
the Numbers from 1 to 10

Wod( 1 -
wxl 1 isg 10 olajd ixLHd
m%o¾Ykh i|yd we,af.dß;u
ks¾udKh
Grade 11 – ICT Unit 9 Programming

NO Condition
fldkafoaish

YES
Grade 11 – ICT Unit 9 Programming

Start N=7+18
N=6+17
N=4+15
N=8+19
N=1+12
N=9+110
N=2+13
N=5+16 1
2
N=1 N=10+111
11 < 10 3
4
No 5
N < 10 N=N+1 6
7
Yes DISPLAY 8
Stop 9
N 10
Grade 11 – ICT Unit 9 Programming

while <condition>
<true statement>
.......
.......
end while
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

BEGIN
N=1
WHILE N<=10
DISPLAY N
N=N+1
END WHILE
END.
Grade 11 – ICT Unit 9 Programming

END WHILE
Grade 11 – ICT Unit 9 Programming

Exercises
1. To print odd numbers from 1 to 10
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

To print odd numbers from 1


to 10
Grade 11 – ICT Unit 9 Programming

Start 1
3
N=1 5
7
No 9
N < 10 N=N+2
Yes DISPLAY
Stop N
Grade 11 – ICT Unit 9 Programming

2. To print Even numbers from


20 to 50
Grade 11 – ICT Unit 9 Programming

Start
20
22
N=20 24
.
No .
N < 50 N=N+2 50
Yes DISPLAY
Stop
N
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

Start N=7+18
N=6+17
N=4+15
N=8+19
N=1+12
N=9+110
N=2+13
N=5+16 21
23
N=21 N=10+111
11 < 10 25
27
No 29
N < 50 N=N+2 31
33
Yes DISPLAY .
Stop .
N 49
Grade 11 – ICT Unit 9 Programming

Start N=7+18
N=6+17
N=4+15
N=8+19
N=1+12
N=9+110
N=2+13
N=5+16 21
23
N=21 N=10+111
11 < 10 25
27
No 29
N < 50 N=N+2 31
33
Yes DISPLAY .
Stop .
N 49
Grade 11 – ICT Unit 9 Programming

BEGIN
N=21
WHILE N<=50
DISPLAY N
N=N+2
END WHILE
END.
Grade 11 – ICT Unit 9 Programming

Start N=7+18
N=6+17
N=4+15
N=8+19
N=1+12
N=9+110
N=2+13
N=5+16 5
10
N=5 N=10+111
11 < 10 15
20
No 25
N < 100 N=N+5 30
.
Yes DISPLAY .
Stop .
N 100
Grade 11 – ICT Unit 9 Programming

BEGIN
N=5
WHILE N<=100
DISPLAY N
N=N+5
END WHILE
END.
Grade 11 – ICT Unit 9 Programming

Develop the Algorithms to display multiple


values of seven from 1 to 100 in descending
order.
Grade 11 – ICT Unit 9 Programming

Start N=7+18
N=6+17
N=4+15
N=8+19
N=1+12
N=9+110
N=2+13
N=5+16 98
91
N=98 N=10+111
11 < 10 84
77
No 70
N>1 N=N-7 63
.
Yes DISPLAY .
Stop .
N 7
Grade 11 – ICT Unit 9 Programming

BEGIN
N=98
WHILE N>=1
DISPLAY N
N=N+7
END WHILE
END.
Grade 11 – ICT Unit 9 Programming

Start 1
2
3
N=1
4
YES 5
N > 10 N=N+1 6
7
NO DISPLAY 8
Stop N 9
10
Grade 11 – ICT Unit 9 Programming

3. Iteration / Repetition

1. FOR….DO

2. WHILE…..LOOP

3. REPEAT……. UNTIL
Grade 11 – ICT Unit 9 Programming

1. FOR….DO
FOR – DO structure can be used
when the number of repetitions is
known in advance.
FOR - DO jHqyhla Ndú; l< yels jkafka
mqk¾lrKh jk jdr .Kk ksYaÑ; j
okafka kï mu‚'
Grade 11 – ICT Unit 9 Programming

1. FOR….DO 1
2
BEGIN
BEGIN 3
N=1
FOR N= 1 TO 10 STEP 2 DO 4
WHILE N<=10
DISPLAY N DISPLAY N 5
NEXT N N=N+1 6
END. END WHILE 7
END. 8
9
10
Grade 11 – ICT Unit 9 Programming

2. FOR….DO ONADI
ONADI
BEGIN
ONADI
FOR N= 1 TO 10 DO
ONADI
DISPLAY “ONADI”
..
NEXT N ONADI
END.
Grade 11 – ICT Unit 9 Programming

3. FOR….DO ONADI
ONADI
BEGIN
ONADI
FOR N= 20 TO 50 (STEP2) DO
ONADI
DISPLAY N
..
NEXT N ONADI
END.
Grade 11 – ICT Unit 9 Programming

3. FOR….DO 2
4
BEGIN 6
FOR N= 2 TO 20 (STEP 2) DO .
DISPLAY N .
NEXT N .
END. .
20
Grade 11 – ICT Unit 9 Programming

4. FOR….DO 2
1-10 IN DESCENDING ORDER
4
BEGIN 6
FOR N= 10 TO 2 (STEP -1) DO .
DISPLAY N .
NEXT N .
END. .
20
Grade 11 – ICT Unit 9 Programming

4. FOR….DO ONADI
ONADI
BEGIN
ONADI
FOR N= 19 TO 1 (STEP-2) DO
ONADI
DISPLAY N
..
NEXT N ONADI
END.
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

TO PRINT ODD NUMBERS FROM 1 TO 10


Grade 11 – ICT Unit 9 Programming

multiple values of 5 from 1 to 100


Begin
For n= 5 to 100 (step 5) do
display n
Next n
End.
Grade 11 – ICT Unit 9 Programming

multiple values of 7 from 1 to 100


descending order
Begin
For n= 98 to 1 step -7 do
display n
Next n
End.
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

30-50 Ascending order


80-20 in descending order
To print the name in 20 times

TO PRINT 20 TO 10 IN DESCENDING ORDER USING [Link] LOOP


Grade 11 – ICT Unit 9 Programming

Write the Pascal program to get the given


star pattern

*
**
***
****
*****
Grade 11 – ICT Unit 9 Programming

3. FOR….DO
to print even numbers from 20
to 50 20
BEGIN
21
FOR N= 20 TO 50 (step 2 ) DO
.
DISPLAY N
.
NEXT N
50
END.
Grade 11 – ICT Unit 9 Programming

3. FOR….DO
to print numbers from 5 to 30
(In descending order) 20
BEGIN BEGIN 21
FOR N= 29 DOWNTO 6 DO FOR N= 29 TO 6 STEP -1 DO .
DISPLAY N DISPLAY N .
NEXT N NEXT N 50
END. END.
Grade 11 – ICT Unit 9 Programming

Ravi
E.g.2- To display your name in ten Ravi
Times. Ravi
BEGIN
FOR N= 1 TO 10 DO Ravi Ravi
Display “Ravi”
Ravi
NEXT N
Ravi
Ravi
END.
Ravi
Ravi
Ravi
Grade 11 – ICT Unit 9 Programming

• When the number of repetitions are not


known in advance, ''While do'' or ''repeat
until'' structures are used.
mqk¾lrK jdr .Kk wúksYaÑ; wjia:dj, §
while do jHqyh iy repeat until jHqyh Ndú;
fõ'
Grade 11 – ICT Unit 9 Programming

2. WHILE…..LOOP
• Conditions are checked at the beginning
of the loop.
• Statements inside the loop are executed
(ie: a loop that runs for ever) only if the
condition is true.
• mqk¾lrKh wdrïNfha § u fldkafoaish mÍlaId
flf¾'
• fldkafoaish i;H jkafka kï muKla mqk¾lrKh
wdrïN fõ'
Grade 11 – ICT Unit 9 Programming

2. WHILE…..LOOP jHqyh
• mqk¾lrKh wdrïNfha § u fldkafoaish
mÍlaId flf¾'
• fldkafoaish i;H jkafka kï muKla
mqk¾lrKh wdrïN fõ'
Grade 11 – ICT Unit 9 Programming

2. WHILE…..LOOP

WHILE CONDITION

STATEMENT

STATEMENT

END WHILE /LOOP


Grade 11 – ICT Unit 9 Programming

E.g. 1- Develop the Algorithm to display the


Numbers from 1 to 10.
Begin
N=1
while N< 10
print N
N= N+1
End while
End.
Grade 11 – ICT Unit 9 Programming

E.g. 1- Develop the Algorithm to display the


Numbers from 1 to 10. Output

Begin 1
N=1 2
while N< 10 3
N
print N yes 4
N= N+1 …
End while 9
End. 10
N
Grade 11 – ICT Unit 9 Programming

Ravi
E.g.2- To print your name in ten Ravi
Times. Ravi
BEGIN
N=1 Ravi Ravi
WHILE N < 10 Ravi
PRINT “Ravi” Ravi
N = N+1 Ravi
END WHILE Ravi
END. Ravi
Ravi
Grade 11 – ICT Unit 9 Programming

E.g. 3-
Develop the Algorithm to display
the Even Numbers from 1 to 20

Wod( 3 -
wxl 1 isg 20 olajd we;s brÜfÜ
ixLHd m%o¾Ykh lsÍu i|yd
we,af.dß;u ks¾udKh
Grade 11 – ICT Unit 9 Programming

Flow chart Start N=6+28


N=2+24
N=4+26
N=8+210
2
N=10+212 4
N=2 6
8
No .
N < 20 N=N+2 .
20
Yes DISPLAY
Stop N
Grade 11 – ICT Unit 9 Programming

Pseudo code Output


Begin 2
N=2 4
while N< 20 6
print N yes 8
N= N+2 10
End while
End.
Grade 11 – ICT Unit 9 Programming

E.g. 4-
Develop the Algorithm to display
the Odd Numbers from 20 to 50

Wod( 4 -
wxl 20 isg 50 olajd we;s
T;af;A ixLHd m%o¾Ykh lsÍu
i|yd we,af.dß;u ks¾udKh
Grade 11 – ICT Unit 9 Programming

Start Flow chart

N=21 21
23
No 25
N < 50 N=N+2 .
Yes 49
DISPLAY
Stop N
Grade 11 – ICT Unit 9 Programming

E.g. 5-
Develop the Algorithm to display the
multiple values of 5 from 1 to 100
Wod( 5 -
wxl 1 isg 100 olajd we;s mfyA .=Kdldr
m%o¾Ykh lsÍu i|yd we,af.dß;u
ks¾udKh lsÍu
Grade 11 – ICT Unit 9 Programming

Start Flow chart

N=5 5
10
No 15
N < 100 N=N+5 .
Yes 100
DISPLAY
Stop N
Grade 11 – ICT Unit 9 Programming

Pseudo code
Begin Output
N=5 Begin 5
while N< 100 for n= 5 to 100 step 5
Display N Display n 10
N= N+5 next n ..
End while End. 100
End.
Grade 11 – ICT Unit 9 Programming

E.g. 6-
Develop the Algorithm to display
the multiple values of 10 in
between 1 and 100 descending
order.
Grade 11 – ICT Unit 9 Programming

Start Flow chart

N=90 90
80
No 70
N>1 N=N-10 .
Yes 10
DISPLAY
Stop N
Grade 11 – ICT Unit 9 Programming

Pseudo code
begin Output
N=90 begin 90
while N>1 For N =90 down to 10 step -10 80
diplay N
diplay N Next N ..
N=N-10 end.
10
End while
end.
Grade 11 – ICT Unit 9 Programming

E.g. 7-
Develop the Algorithm to display
the Even numbers between 20 and
40 in descending order.
Grade 11 – ICT Unit 9 Programming

Start Flow chart

N=38 38
36
No 34
N > 20 N=N-2 .
Yes 22
DISPLAY
Stop N
Grade 11 – ICT Unit 9 Programming

Pseudo code
begin Output
N=38 5
while N>20
Display N 10
N=N-2 ..
End while 100
end.
Grade 11 – ICT Unit 9 Programming

E.g. 8-
Develop the Algorithm to display
the multiple values of 7 from 1 to
50 in descending order.
Grade 11 – ICT Unit 9 Programming

Start Flow chart

N=49 49
42
No 35
N>1 N=N-7 .
Yes 7
DISPLAY
Stop N
Grade 11 – ICT Unit 9 Programming

Pseudo code
begin Output
N=49 5
while N>=1
Diplay N 10
N=N-7 ..
End while 100
end.
Grade 11 – ICT Unit 9 Programming

E.g. 9-
Develop the Algorithm to display
the squared Numbers from 1 to
100
Wod( 9 -
wxl 1 isg 100 olajd we;s j¾.
ixLHd m%o¾Ykh lsÍu i|yd
we,af.dß;u ks¾udKh
Grade 11 – ICT Unit 9 Programming

n sq
1x1=1
2x2 =4
3x3= 9 n n sq
4 x 4 = 16
. n+1 n+1 sq
.
10 x 10 =100
Grade 11 – ICT Unit 9 Programming

Start Flow chart


1
Sq=1 4
121<100 sq=6x636
sq=10x10100
sq=5x525
sq=11x11121
sq=9x981
sq=7x749
sq=4x416
sq=8x864
sq=3x39
sq=2x24
N=1 9
sq=NxN 16
No 25
N=N+1 36
sq < 100 49
DISPLAY 64
Stop Yes sq 81
N=9+110
N=8+19
N=6+17
N=5+16
N=7+18
N=4+15 100
N=10+111
N=2+13
N=3+14
N=1+12
Grade 11 – ICT Unit 9 Programming

Pseudo code
Begin
N=1, sq=1
Output
While sq<=100
1
Diplay sq
N=N+1 4
sq=N x N 9
End while ..
end. 100
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

Start Flow chart


T=N(N+1)/2 1
T=1 3
N=1 6
T=T+N 10
No 15
N=N+1 21
T >100 28
DISPLAY 36
Stop Yes T .
91
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

E.g. 9-
Develop the Algorithm to display the
Triangular Numbers from 1 to 100

Wod( 9 -
wxl 1 isg 100 olajd we;s j¾.
ixLHd m%o¾Ykh lsÍu i|yd
we,af.dß;u ks¾udKh
Grade 11 – ICT Unit 9 Programming

Start Flow chart


T=N(N+1)/2
1
T=1 3
N=1 6
T=T+N 10
15
Yes N=N+1 21
T > 100 29
DISPLAY 38
Stop .
No T
.
Grade 11 – ICT Unit 9 Programming

Start Flow chart Sri Lanka


Sri Lanka
N=1 Sri Lanka
Sri Lanka
Sri Lanka
Sri Lanka
Sri Lanka
No N=N+1 Sri Lanka
Sri Lanka
N < 10 Sri Lanka
Stop DISPLAY
My
“I LOVE MY COUNTRY Sri Motherlan
Yes Lanka” d
Grade 11 – ICT Unit 9 Programming

BEGIN BEGIN
T=1 T=1
N=1 count=1
while T<=100 while T<=100:
DISPLAY T display T
N=N+1 count =count+1
T=(count*(count+1))/2
T=T+N
END WHILE
LOOP/END WHILE END
END.
Grade 11 – ICT Unit 9 Programming

Begin
for n= 1 to 10 do
display "Sri Lanka"
next n
Display "I Love My Motherland"
end.
Grade 11 – ICT Unit 9 Programming

Start Flow chart Sri Lanka


Sri Lanka
N=1 Sri Lanka
Sri Lanka
Sri Lanka
Sri Lanka
Sri Lanka
No N=N+1 Sri Lanka
Sri Lanka
N < 10 Sri Lanka
DISPLAY My
“My motherland” DISPLAY Motherlan
Yes “Sri Lanka d
Stop
Grade 11 – ICT Unit 9 Programming

Last week Home Work…


Grade 11 – ICT Unit 9 Programming

E.g. 4-
Develop the Algorithm to display
the Odd Numbers from 20 to 50

Wod( 4 -
wxl 20 isg 50 olajd we;s
T;af;A ixLHd m%o¾Ykh lsÍu
i|yd we,af.dß;u ks¾udKh
Grade 11 – ICT Unit 9 Programming

Start Flow chart

N=21 21
23
No 25
N < 50 N=N+2 .
Yes 49
DISPLAY
Stop N
Grade 11 – ICT Unit 9 Programming

MULTIPLE VALUES OF 5 FROM 5 TO 100


Grade 11 – ICT Unit 9 Programming

Start Flow chart


5
10
N=5
15
No 20
N < 100 N=N+5 25
.
Yes DISPLAY .
Stop N 100
Grade 11 – ICT Unit 9 Programming

MULTIPLE VALUES OF 7 FROM 1 TO 100 IN


DESCENDING ORDER.
Grade 11 – ICT Unit 9 Programming

Start Flow chart


98
91
N=98
84
No 77
N>1 N=N-7 70
.
Yes DISPLAY .
Stop N 7
Grade 11 – ICT Unit 9 Programming

Answer
Grade 11 – ICT Unit 9 Programming

Pseudo code
Begin Output
N=21 21
while N< 50
print N 23
yes
N= N+2 ..
End while 49
End.
Grade 11 – ICT Unit 9 Programming

Not satisfied
;Dma; fkdfõ
Condition
fldkafoaish
Satisfied
;Dma; fõ
Grade 11 – ICT Unit 9 Programming

Start Flow chart

N=5 5
10
No 15
N < 100 N=N+5 .
Yes 100
DISPLAY
Stop N
N
Grade 11 – ICT Unit 9 Programming

E.g. 3- Develop the Algorithm to display the


Even Numbers from 1 to 10.
Begin Output
N=5 5
while N< 100
10
print N yes
N= N+5 ….
End while
End. 100
Grade 11 – ICT Unit 9 Programming

3. Iteration / Repetition

1. FOR….DO

2. WHILE…..LOOP

3. REPEAT……. UNTIL
Grade 11 – ICT Unit 9 Programming

3. REPEAT……. UNTIL
• Condition is not checked at the
beginning of loop.
• Condition is checked, after the
statements are executed once.
• Loop is started if the condition is false
only.
Grade 11 – ICT Unit 9 Programming

3. REPEAT……. UNTIL jHqyh


• mqk¾lrKh wdrïNfha § u fldkafoaish
mÍlaId fkd flf¾'
• mqk¾lrKh ùug we;s m%ldYk tla jrla
l%shd;aul ùfuka miq j fldkafoaish
mÍlaId flf¾'
• fldkafoaish wi;H jkafka kï muKla
mqk¾lrKh ùu wdrïN fõ'
Grade 11 – ICT Unit 9 Programming

Compare While...do loop and Repeat ...Until Loop.


While...do loop Repeat ...Until

Condition is checked at the beginning Condition is not checked at the


of loop. beginning of loop.
Statements inside the loop are Condition is checked, after the
executed (ie: a loop that runs for statements are executed once.
ever) only if the condition is true.
Loop is started if the condition is true Loop is started if the condition is false
only. only.
Grade 11 – ICT Unit 9 Programming

STATEMENT

Satisfied
;Dma; fõ Condition
fldkafoaish
Not satisfied
;Dma; fkdfõ
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

BEGIN 2
N=2 4
N=2
REPEAT 6
DISPLAY N 8
DISPLAY N
N=N+2 10
N=N+2
UNTIL N>10
NO
END N>10

YES
Grade 11 – ICT Unit 9 Programming

BEGIN
N=1
REPEAT
DISPLAY N
N=N+2
UNTIL N>10
END
Grade 11 – ICT Unit 9 Programming

BEGIN
N=21
REPEAT
DISPLAY N
N=N+2
UNTIL N>50
END
Grade 11 – ICT Unit 9 Programming

3. REPEAT…..UNTIL LOOP
REPEAT
STATEMENT

STATEMENT

UNTIL CONDITION
Grade 11 – ICT Unit 9 Programming

3. REPEAT…..UNTIL LOOP
REPEAT
STATEMENT

STATEMENT

UNTIL fldkafoaish
Grade 11 – ICT Unit 9 Programming

START
EX2
BEGIN N=2
N=2
REPEAT DISPLAY N

DISPLAY N
N=N+2 N=N+2
UNTIL N>10
NO
END. N>10

YES
STOP
Grade 11 – ICT Unit 9 Programming

START
EX3
BEGIN N=2

N=2
REPEAT DISPLAY N

DISPLAY N
N=N+2
N=N+2
UNTIL N>10 NO

END. N>10

YES

STOP
Grade 11 – ICT Unit 9 Programming
Grade 11 – ICT Unit 9 Programming

E.g. 1-
Develop the Algorithm to display
the Numbers from 1 to 10

Wod( 1 -
wxl 1 isg 10 olajd ixLHd m%o¾Ykh
i|yd we,af.dß;u ks¾udKh
Grade 11 – ICT Unit 9 Programming

Start Flow chart N=3+14


N=7+18
N=6+17
N=4+15
N=8+19
N=1+12
N=9+110
N=2+13
N=5+16 1
2
N=100 No N=10+111 3
4
Yes
5
DISPLAY N > 10 6
N 7
8
N=N+1 Stop 9
10
Grade 11 – ICT Unit 9 Programming

Pseudo code 1
BEGIN 2
N=1 3
REPEAT 4
PRINT N 5
6
N= N+1
7
UNTIL N > 10 8
END. 9
10
Grade 11 – ICT Unit 9 Programming

Ravi
E.g. 2 - To print your name in ten Ravi
Times. Ravi
BEGIN
N=1 Ravi Ravi
Ravi
REPEAT
Ravi
DISPLAY “Ravi” Ravi
N=N+1 Ravi
UNTIL N>10 Ravi
END. Ravi
Grade 11 – ICT Unit 9 Programming

Start Flow chart N=3+14


N=7+18
N=6+17
N=4+15
N=8+19
N=1+12
N=9+110
N=2+13
N=5+16 Ravi
Ravi
N=1 No N=10+111 Ravi
Ravi
Yes
Ravi
DISPLAY N > 10 Ravi
“Ravi” Ravi
Ravi
N=N+1 Stop Ravi
Ravi
Grade 11 – ICT Unit 9 Programming

E.g. 3-
Develop the Algorithm to display
the Even Numbers from 1 to 10

Wod( 3 -
wxl 1 isg 10 olajd we;s brÜfÜ
ixLHd m%o¾Ykh lsÍu i|yd
we,af.dß;u ks¾udKh
Grade 11 – ICT Unit 9 Programming

Start Flow chart N=6+28


N=2+22
N=8+210
N=4+26

N=2 No N=10+212 2
4
Yes
6
DISPLAY N > 10 8
N 10

N=N+2 Stop
Grade 11 – ICT Unit 9 Programming

BEGIN
Pseudo code
N=2
N=8+210
N=4+26
N=6+28
N=2+24
REPEAT 2
PRINT N 4
N= N+2 6
UNTIL N > 10 8
END. 10
N=10+212
Grade 11 – ICT Unit 9 Programming

E.g. 4-
Develop the Algorithm to display
the MULTIPLE VALUES OF 3 from 1
to 100 in Descending order

Wod( 3 -
Grade 11 – ICT Unit 9 Programming

Start Flow chart N=6+28


N=2+22
N=8+210
N=4+26

N=99 No N=10+212 99
96
Yes
93
DISPLAY N<1 .
N 3

N=N-3 Stop
Grade 11 – ICT Unit 9 Programming

BEGIN
Pseudo code
N=99 N=93-390
N=6-33
N=99-396
N=96-393
REPEAT 99
PRINT N 96
N= N-3 93
UNTIL N < 1 .
END. 3
N=3-30
Grade 11 – ICT Unit 9 Programming

E.g. 4-
Develop the Algorithm to display
the Odd Numbers from 20 to 50

Wod( 4 -
wxl 20 isg 50 olajd we;s T;af;A
ixLHd m%o¾Ykh lsÍu i|yd
we,af.dß;u ks¾udKh
Grade 11 – ICT Unit 9 Programming

Start Flow chart


N=47+249
N=25+227
N=21+223
N=23+225
N=21 No 51 >50
N=49+251 21
23
Yes
25
DISPLAY N > 50 27
N …
49
N=N+2 Stop
Grade 11 – ICT Unit 9 Programming

Pseudo code
BEGIN N=47+249
N=25+227
N=21+223
N=23+225
N=21
N=49+251 21
REPEAT
23
PRINT N 51 >50 25
N= N+2 27
YES
UNTIL N > 50 …
49
END.
Grade 11 – ICT Unit 9 Programming

Pseudo code
BEGIN BEGIN
N=21 21
23
N=21
REPEAT 25 WHILE N< 50
PRINT N 27 PRINT N
N= N+2 … N= N+2
49 END WHILE
UNTIL N > 50
END.
END.
Grade 11 – ICT Unit 9 Programming

E.g. 5-
Develop the Algorithm to display the
squared Numbers from 1 to 100

Wod( 5 -
wxl 1 isg 100 olajd we;s j¾. ixLHd
m%o¾Ykh lsÍu i|yd we,af.dß;u
ks¾udKh
Grade 11 – ICT Unit 9 Programming

n sq
1x1=1
2x2 =4
3x3= 9 n n sq
4 x 4 = 16
. n+1 n+1 sq
.
10 x 10 =100
Grade 11 – ICT Unit 9 Programming

Start Flow chart 1


N=1 121>100 4
Sq=1 No 9
16
Yes 25
DISPLAY sq> 100 36
sq 49
64
N=N+1 sq=NxN Stop 81
100
N=9+110
N=8+19
N=6+17
N=5+16
N=7+18
N=4+15
N=10+111
N=2+13
N=3+14
N=1+12 sq=6x636
sq=10x10100
sq=5x525
sq=11x11121
sq=9x981
sq=7x749
sq=4x416
sq=8x864
sq=3x39
sq=2x24
Grade 11 – ICT Unit 9 Programming

Pseudo code
BEGIN BEGIN
N=1 21 N=1
SQ=1 23 SQ=1
REPEAT 25 WHILE SQ<=100
DISPLAY SQ 27 DISPLAY SQ
N= N+1 …
N= N+1
49
SQ=NXN SQ=NXN
UNTIL SQ > 100 END WILE
END. END.
Grade 11 – ICT Unit 9 Programming

Pseudo code
Begin
N=1 Output
Sq=1 1
Repeat
4
print sq
N= N+1 9
NO ..
sq=N x N
Until sq > 100 100
End.
Grade 11 – ICT Unit 9 Programming

Develop the Algorithm using Repeat..Until


loop to display the multiple values of 5
from 1 to 100.
wxl 1 isg 100 olajd we;s mfyA .=Kdldr
m%o¾Ykh lsÍu i|yd we,af.dß;u
ks¾udKh (Repeat..Until) lrkAk'
Grade 11 – ICT Unit 9 Programming

T=N(N+1)/2

T=T+N
Grade 11 – ICT Unit 9 Programming

Start Flow chart


N=47+249
N=25+227
N=21+223
N=23+225
N=5 No 102 >100
N=49+251 5
10
Yes
15
DISPLAY N > 100 20
N …
100
N=N+5 Stop
Grade 11 – ICT Unit 9 Programming

Start Flow chart


N=5 No
Yes
DISPLAY N > 100
N

N=N+5 Stop
Grade 11 – ICT Unit 9 Programming

Pseudo code
BEGIN BEGIN
N=5 21
23
N=5
REPEAT 25 While N<=100
PRINT N 27 PRINT N
N= N+5 …
N= N+5
49
UNTIL N > 100 End while
END. END.
Grade 11 – ICT Unit 9 Programming

Summery
Grade 11 – ICT Unit 9 Programming
GRADE - 13 ICT PROGRAMMING - 09

Last week Home Work…


GRADE - 13 ICT PROGRAMMING - 09

Develop the Algorithm using Repeat.. Until


loop to display the multiple values of 5
from 1 to 100.
wxl 1 isg 100 olajd we;s mfyA .=Kdldr
m%o¾Ykh lsÍu i|yd we,af.dß;u
ks¾udKh (Repeat.. Until) lrkAk'
GRADE - 13 ICT PROGRAMMING - 09
GRADE - 13 ICT PROGRAMMING - 09

Answer
GRADE - 13 ICT PROGRAMMING - 09

Flow chart 5
Start 10
15
20
N=5 25
30
No 35
40
N < 100 N=N+5 45
50
Yes DISPLAY 55
Stop N .
.
100
GRADE - 13 ICT PROGRAMMING - 09

Start Flow chart 5


N=100+5105 10
N=5 No 15
20
Yes 25
DISPLAY N > 100 30
N 35
40
N=N+5 Stop .
N=20+525
N=30+535
N=35+540
N=15+520
N=10+515 .
N=5+510
N=95+5100
N=25+530
100
GRADE - 13 ICT PROGRAMMING - 09

Pseudo code
Begin Begin
N=5 N=5
while N< 100 REPEAT NO
Display N YES Display N
N= N+5 N= N+5
End while UNTIL N>100
End. End.
GRADE - 13 ICT PROGRAMMING - 09

Four Steps of Problem solving


.eg¨ úi£fï mshjr 4 ls'

1. Analyzing the Problem 1' .eg¨j úYaf,aIKh lsÍu


2' .eg¨ úi£u i|yd
2. Creating an Algorithm
for the Problem solving we,af.dß;u [Link]
3'l%uf,ALkh
3. Developing Programs
4'mÍlaId lsÍu iy fodaI
4. Testing and debugging bj;A lsÍu
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

3. Developing the Programs


l%uf,ALkh

created by sandani hettiarachchi


GRADE - 13 ICT PROGRAMMING - 09

created by sandani hettiarachchi


GRADE - 13 ICT PROGRAMMING - 09
Python

• Python is an easy to learn, powerful


programming language.
• It has efficient high-level data
structures and a simple but effective
approach to object-oriented
programming.
• Python is an ideal language for
scripting and rapid application
development in many areas on most
platforms.
GCE (A/L) ICT Training for Teachers
GRADE - 13 ICT PROGRAMMING - 09
Python Language

• No variable, data type declaration


necessary (Dynamically Typed)
• Case Sensitive variables
• Indentation of 4 characters used for
block structures (e.g. if, while,
functions)
• Program extension is .py
• Runs on multiple platforms
• Open Source

GCE (A/L) ICT Training for Teachers


GRADE - 13 ICT PROGRAMMING - 09
Python Keywords

• Like most modern languages Python


has only a few keywords.

GCE (A/L) ICT Training for Teachers


GRADE - 13 ICT PROGRAMMING - 09

History
• Developed in the early
1990s by Guido van
Rossum.
• The name Python was
based a popular TV show
called the Monty Python.

GCE (A/L) ICT Training for Teachers


GRADE - 13 ICT PROGRAMMING - 09

Python programming
1.4.1 Identifiers 1.4.1 y÷kajk
An identifier is a
term used to y÷kajkhla hkq
represent
• úp,Hhla (Variable)
• a variable,
• ksh;hla (Constant)
• a constant or
• l%uf,aLkhla (Program)
• a name for a
program. ioyd Ndú; lrk kuls'
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

Some rules…
(1) Reserved words in Python cannot be
used as an identifier name.
E.g. - BEGIN, END are not valid
meial,a NdIdj y÷kajd §u i|yd Ndú;
lrkq ,nk wejqreKq mo (Reserved words)
fhdod fkd.; hq;= h'

created by sandani hettiarachchi


GRADE - 13 ICT PROGRAMMING - 09

Reserved words and


exports inherited of then asm
file inline or to array
for interface packed type begin
function label procedure unit case
goto library program until const
if mod record uses constructor
implementation nil repeat var destructor
In not set while div
else object shl with do
end xor shr ate downto
string to
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

created by sandani hettiarachchi


GRADE - 13 ICT PROGRAMMING - 09

• Should start with an English letter.


• bx.%Sis fydaäfha wlaIrhlska wdrïN l< hq;=
h' (eg : A-Z, a-z)

Wod - Student2

2Student

created by sandani hettiarachchi


GRADE - 13 ICT PROGRAMMING - 09

• After the first letter of the identifier, letters


(a-z, A-Z) or numbers (0-9) and underscore
( _ ) can be used.
• y÷kajkfha m<uq wËrhg miqj wËr (a-z,
A-Z) fyda ixLHdxl (0-9) iy há br (_)
fhdod .; yelsh'

Wod- Student_name

created by sandani hettiarachchi


GRADE - 13 ICT PROGRAMMING - 09

•Not case sensitive (E.g. - Art, art, ART will


be the same identifier)
•meial,a NdIdfõ § y÷kajk i|yd wlaIr
fíoh n, fkdmdhs'
^WÞ - Art, art, ART hkq tl u
y÷kajkhls'&

created by sandani hettiarachchi


GRADE - 13 ICT PROGRAMMING - 09

There should not be any space


between words.
E.g. - Student Name - Not valid

jpk w;r mr;rhla (space)


fkdmej;sh hq;= h'
Wod - Student Name - j,x.= ke;'
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

The special characters such as the


following should not be included in
an identifier. y÷kajkhla ;=< my;
wkq,laIK wvx.= fkdúh hq;= h'
~ ! @ # $ % ^ & * ( ) - + = { } [ ] : ; ‘ “ <> ? , . / | \

but, only underscore ( _ ) is valid.


kuq;a há br (underscore _ ) ,l=K
muKla j,x.= fõ'
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

•Use of meaningful terms for identifiers


can make program easily understood.
² y÷kajk i|yd w¾:j;a kdu fhdod
.ekSfuka l%uf,aL f;areï .ekSug
myiq fõ'
x ?
number
Num
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

Find valid identifiers


•SUM valid

•Average Marks not valid

•Total_Nos valid

•$75 not valid


created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

Find valid identifiers


• Num1 valid

• FirstName valid

• Last_Name valid

• cost@ not valid


• 9A not valid
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

Standard data types in Pascal


meial,a NdIdfõ iïu; o;a; m%rEm
When a program is executed, the input and
output should be stored in computer
memory.
l%uf,aLh l%shd;aul jk úg wdodk iy
m%;sodk l%shdj,sh ;=< r|jd ;nd .ekSug
wjYH fõ'
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

Standard data types in Pascal


meial,a NdIdfõ iïu; o;a; m%rEm
•Integer - Ok fyda RK ksÅ, ixLHd$mQ¾K
ixLHd
Wod - 0" 46" -12

•Real - Ok fyda RK ;d;aúl ixLHd$oYu


ixLHd
Wod - 0'0" 25'68
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

Standard data types in Pascal


meial,a NdIdfõ iïu; o;a; m%rEm
• Boolean - True fyda False Pass/fail
• Char - h;=re mqjrefõ we;s ´kE u
wkq,laIKhla
Wod - ‘k’, ‘#’, ‘7’

• String - ´kE u wkq,laIK wkql%uhla


Wod -‘ICT’, ‘programming’, 'Sri Lanka'
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

jeo.;a
•Char iy String hk o;a; m%rEm ;ks Wvq
fldud ;=< (‘ ’) (single quotation) olajkq
,efí'

•Values of Char and String are included inside


single quotation ‘ ’.

created by sandani hettiarachchi


GRADE - 13 ICT PROGRAMMING - 09

l%uf,aLkfha § fhdod .kakd úp,H


(variable) iy ksh; (constant)
úp,H (Variable)
l%uf,aLh l%shd;aul jk úg y÷kajkh
i|yd mjrk ,o [Link] fjkia jk
y÷kajk" úp,Hhla f,i kï flf¾'

created by sandani hettiarachchi


GRADE - 13 ICT PROGRAMMING - 09

l%uf,aLkfha § fhdod .kakd úp,H


(variable) iy ksh; (constant)
Variable
A variable is an identifier which changes
the values given to it when the program
is being executed.

created by sandani hettiarachchi


GRADE - 13 ICT PROGRAMMING - 09

meial,a NdIdfõ § úp,H w¾: oelaùu


i|yd —var˜ hk wejqreKq moh fhdod
.efka' 78 ‘hi’
Wod - Var count : integer;
Var a,b : Real; 45.65
Var n1, n2 : integer; ‘s’
Avg : real ; Avg
Pass : boolean;
Character : char; character
Name,school : String;
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

úp,H (variable)

created by sandani hettiarachchi


GRADE - 13 ICT PROGRAMMING - 09

ksh; (Const)
• l%uf,aLh l%shd;aul jk úg y÷kajkh
i|yd mjrk ,o [Link] fjkia fkdjk
y÷kajk" ksh; f,i kï flf¾'
• meial,a NdIdfõ § ksh; w¾: oelaùu
i|yd —const˜ hk wejqreKq moh fhdod .efka'
Wod –
Const max = 100;
Const pi = 22/7;
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

Constant
•The identifiers which do not change
their values while the program is
executed are called constants.
•In Pascal, “const” is used to declare a
constant.
Example –
Const max = 100;
Const pi = 22/7;
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09

ldrl (Operators)
Basic types of operators
1' wxl .‚;uh ldrl Arithmetical
operators
2' iei֕ ldrl Comparison operator
3' ;d¾lsl ldrl Logical operators
created by sandani hettiarachchi
GRADE - 13 ICT PROGRAMMING - 09
Selection

if (cond) then
Statement A

else
Statement B

endif

GCE (A/L) ICT Training for Teachers


GRADE - 13 ICT PROGRAMMING - 09
Selection

if (cond) then
Statement A

else if cond:
Statement B Statement A
… …
endif else:
Statement B

GCE (A/L) ICT Training for Teachers


GRADE - 13 ICT PROGRAMMING - 09
if statement

• Write a program to input a mark and


display Pass if it is greater than or
equal to 50. Otherwise display Fail.

GCE (A/L) ICT Training for Teachers


GRADE - 13 ICT PROGRAMMING - 09
if statement

• Write a program to input a number.


Display if it is an even or an odd
number.

[Link]

GCE (A/L) ICT Training for Teachers


Grade 11 ICT PROGRAMMING 08

Wod –

1' NOT ^100 > 30& False


2' NOT (5 = 5) False
5 = 5 hk m%ldYkh i;H fõ'
tneúka NOT(5 = 5) hk m%ldYkh wi;H
f,i olajhs'

created by sandani hettiarachchi


Grade 11 ICT PROGRAMMING 08

ldrl m%uqL;dj Operator precedence

created by sandani hettiarachchi


Grade 11 ICT PROGRAMMING 08

Evaluating expressions.
meial,a m%ldYk [Link] lrk whqre .
WÞ -- ^1& 3 DIV
4 14
5 + 14 MOD 4 12
5+2 2
7 MOD

created by sandani hettiarachchi


Grade 11 ICT PROGRAMMING 08

Evaluating expressions.
meial,a m%ldYk [Link] lrk whqre .
WÞ -- ^2& 3 DIV
2 7
3 + 7 DIV 2 6
3+3 1
6 MOD

created by sandani hettiarachchi


Grade 11 ICT PROGRAMMING 08

Evaluating expressions.
meial,a m%ldYk [Link] lrk whqre .
WÞ -- ^3& 4
4 16
16/4 * 2 16
4*2 0
8

created by sandani hettiarachchi


Grade 11 ICT PROGRAMMING 08

Evaluating expressions.
meial,a m%ldYk [Link] lrk whqre .
WÞ -- ^4& 4 DIV
2 8
NOT (8 MOD 2 >5) 8
NOT(0> 5) 0
NOT(False) MOD
True
created by sandani hettiarachchi
Grade 11 ICT PROGRAMMING 08

Evaluating expressions.
meial,a m%ldYk [Link] lrk whqre .
WÞ -- ^4&
4>= 4 AND NOT (7 >9)
TRUE AND NOT(False)
True AND True
True
created by sandani hettiarachchi
Grade 11 ICT PROGRAMMING 08

Find the Answer.


1. ((50*2)> 56) AND (50 < 30)
2. (100 > 60) AND ((100 DIV 2) < 15)
3. (100> 56) OR ((100/2) < 30)
4. (30 > (30*2)) OR (100 < 15)
5. NOT(20>10 AND 30>100)
created by sandani hettiarachchi
Grade 11 - ICT Unit 1 Programming - 09

Last week Home Work…


ani hettiarachchi
Grade 11 - ICT Unit 1 Programming - 09

ldrl m%uqL;dj Operator precedence


ani hettiarachchi
Grade 11 - ICT Unit 1 Programming - 09

Find the Answer.


1. ((50*2)> 56) AND (50 < 30)
2. (100 > 60) AND ((100 DIV 2) < 15)
3. (100> 56) OR ((100/2) < 30)
4. (30 > (30*2)) OR (100 < 15)
5. NOT(20>10 AND 30>100)
Grade 11 - ICT Unit 1 Programming - 09

Answer
ani hettiarachchi
Grade 11 - ICT Unit 1 Programming - 09

Evaluating expressions.

^1& ((50*2)> 56) AND (50 < 30)


(100> 56) AND (50 < 30)
(True) AND (False)
False
Grade 11 - ICT Unit 1 Programming - 09

Evaluating expressions.
DIV

^2& (100 > 60) AND ((100 DIV 2) < 15) 50


2 100
(True) AND (50 < 15) 100
(True) AND (False) 0
False
MOD
Grade 11 - ICT Unit 1 Programming - 09

Evaluating expressions.
DIV

^3& (100> 56) OR ((100/2) < 30) 50


2 100
(True) OR (50 < 30) 100
(True) OR (False) 0
True
MOD
Grade 11 - ICT Unit 1 Programming - 09

Evaluating expressions.

^4& (30 > (30*2)) OR (100 < 15)


(30 > 60) OR (100 < 15)
(False) OR (False)
False
Grade 11 - ICT Unit 1 Programming - 09

Evaluating expressions.

^5& NOT(20>10 AND 30>100)


NOT(True AND False)
NOT(False)
True
Grade 11 - ICT Unit 1 Programming - 09

Let us identify the basic components


of a normal Pascal program.
idudkH meial,a l%uf,aLhl wvx.=
uQ,sl fldgia y÷kd .ksuq'
Grade 11 - ICT Unit 1 Programming - 09

program addNum (input,output);


var num1,num2,total : integer; Declaring the
avg: real; variables
Begin Beginning of the main program
Write(‘Welcome Pascal Programming’);
{calculate total and average of two numbers}
Writeln(‘Enter First Number’);
Read(num1); Input
Grade 11 - ICT Unit 1 Programming - 09

Writeln(‘Enter Second Number’); Input


Read(num2);
total: =num1 + num 2; Expressions
which indicate
avg := total/2;
the process
writeln(‘Total is ‘ , total);
Output
writeln(‘Average is ‘ , avg);
End.
(*..............*) can also be used
Grade 11 - ICT Unit 1 Programming - 09
Grade 11 - ICT Unit 1 Programming - 09

Problem 01 :
Add two numbers and display the
total
.eg¨j 01 (
ixLHd foll tl;=j fiùu
Grade 11 - ICT Unit 1 Programming - 09

Start
.e,Sï igyk INPUT TWO
Flow chart NUMBERS(N1,N2)

TOTAL = N1+N2
BEGIN
Input two Numbers (n1,n2)
Total= n1+n2 DISPLAY TOTAL
Display Total
END Stop
Grade 11 - ICT Unit 1 Programming - 09
Grade 11 - ICT Unit 1 Programming - 09

Problem 02 :
Calculate the average marks of
Three subjects.
.eg¨j 02 (
úIhhka 3l ,l=Kq we;=<;a l<
úg idudkH ,l=Kq .Kkh lsÍu
Grade 11 - ICT Unit 1 Programming - 09

Start
PSEUDO CODE
Input Three Subject
Marks
(mark1,mark2,mark3) BEGIN
Input Three Subject Marks
Average = (mark1,mark2,mark3)
(mark1,mark2,mark3)/3 Average =(mark1,mark2,mark3)
3

Display Average Display Average


END.

Stop
Grade 11 - ICT Unit 1 Programming - 09
Grade 11 - ICT Unit 1 Programming - 09

Problem 03 :
Calculate Area of a rectangle according to
the given length and width

.eg¨j 03 (
iDcqfldaKdi%hl È. , m<, ,nd ÿka úg tys
j¾.M,h .Kkh lsÍu
Grade 11 - ICT Unit 1 Programming - 09

Start
Flow chart
Input length (len)
Width (width) BEGIN
Input length (len), Width
Area = len x Width Area = len x Width
Display Area
END.
Display Area
PSEUDO CODE
Stop
Grade 11 - ICT Unit 1 Programming - 09
Grade 11 - ICT Unit 1 Programming - 09

(2) SELETION
jrKh
Grade 11 - ICT Unit 1 Programming - 09

Ex- The Program to check whether the


given number is Positive Number.

9 ?
Grade 11 - ICT Unit 1 Programming - 09

Start INPUT a
number(N) Pseudocode
BEGIN
Is No INPUT a Number(N)
N>0? IF N>0 THEN
Print “Positive Number”
yes
ENDIF
Display
END.
(“Positive number”)

Flow chart Stop


Grade 11 - ICT Unit 1 Programming - 09

PASCAL CODE
Grade 11 - ICT Unit 1 Programming - 09

Start
.e,Sï igyk
Flow chart INPUT Age

DISPLAY yes
“ADULT” Age >=18
No
DISPLAY “CHILD”
Stop
Grade 11 - ICT Unit 1 Programming - 09

PSEUDO CODE jHdc flA;h


BEGIN
Input Age
If Age >= 18 THEN
Display “Adult”
ELSE
Display “Child”
END IF
END
Grade 11 - ICT Unit 1 Programming - 09

PASCAL CODE
Grade 11 - ICT Unit 1 Programming - 09

.e,Sï igyk Start

Flow chart INPUT a Number(n)

Rem=The remeinder of n/2

yes
Result=“Odd” Rem=1
No
Result=“Even”
DISPLAY Result Stop
Grade 11 - ICT Unit 1 Programming - 09

PSEUDO BEGIN
CODE Input a Number (N)
Rem = the remainder of N/2
IF Rem = 1 THEN
result= “Odd”
ELSE
result= “Even”
ENDIF
Display result
END.
Grade 11 - ICT Unit 1 Programming - 09

Pascal code

Output
Grade 11 - ICT Unit 1 Programming - 10

Selection in repetition
mqk¾lrKh ;=< jrKh
fhdod .ekSu
Grade 11 - ICT Unit 1 Programming - 10

mßYS,l úiska wdodkh lrkq ,nk ixLHd T;af;a


ixLHd o" brÜfÜ ixLHd o" hkak y÷kd .ekSu yd
T;af;a yd brÜfÜ ixLHd m%udK fjk fjk u
.Kkh lsÍu
Determining whether the numbers input by
the user are odd or even and calculating the
total number of odd, even numbers
separately.
Grade 11 - ICT Unit 1 Programming - 10

Start Stop

No yes
COUNT=1 Count INPUT A
E_COUNT=0
< =5 NUMBER(N)
O_COUNT=0
R=the remainder of
N/2
count=count+1
yes
O_count=O_count+1 R=1
E_count=E_count+1
No
Grade 11 - ICT Unit 1 Programming - 10

PSEUDO CODE jHdc flA;h


BEGIN If R= 1 THEN
count=1 O_count=O_count+1
E_count=0 ELSE
O_count=0 E_count= E_count+1
While count<=5 END IF
Count= Count+1
Input a Number(N)
End while
R=remainder of N/2 END.
Grade 11 - ICT Unit 1 Programming - 10

program printnumpattern;
var
i,j:integer;
begin
i:=1;
while i<=10 do
begin
j:=1;
while j<=i do
begin
Grade 11 - ICT Unit 1 Programming - 10
Grade 11 - ICT Unit 1 Programming - 10
Grade 11 - ICT Unit 1 Programming - 10

PASCAL CODE
Grade 11 - ICT Unit 1 Programming - 10

Repetition inside
selection
jrKh ;=< mqk¾lrKh
fhdod .ekSu
Grade 11 - ICT Unit 1 Programming - 10

Start
N=1
INPUT YOUR If yes No
CHOICE(A/D) choice= N<=6
N=6
“A” yes
No
No yes If Display N
N>=1 choice=
yes “D” N=N+1
Display N N=N-1
Stop
Grade 11 - ICT Unit 1 Programming - 10
PSEUDO CODE
BEGIN
Input a Choice (A/D) IF choice = “D” THEN
IF choice = “A” THEN for n=6 downto 1 do
for n=1 to 6 do display (n)
display (n) next n
next n End if
End if END.
Grade 11 - ICT Unit 1 Programming - 10
created by sandani hettiarachchi
Grade 11 - ICT Unit 1 Programming - 10

f;dr;=re yd ikaksfõok
;dlaIKh

11 fY%aKsh
Grade 11 – ICT Unit 9 Programming

Problem solving steps.


1. Analyzing the Problem
2. Creating an Algorithm for the Problem
solving 1. SEQUENCE
3. Developing Programs 2. SELECTION

4. Testing and debugging 3. REPETITION

You might also like