Page 99 - Touchpad_Plus_V3.2_Class 6
P. 99
SOLVING PROBLEMS USING ALGORITHMS AND
FLOWCHARTS
Example 1: Write an algorithm and draw a Example 2: Write an algorithm and draw a
flowchart to calculate the factorial of a flowchart to check weather a given number
number.
is even or odd.
Algorithm Algorithm
Step 1 Start Step 1 Start
Step 2 Read the number n
Step 2 Read the number n
Step 3 Initialize i=1, fact=1
Step 3 Check If Number % 2 == 0 Then
Step 4 Check If i < = n Then Repeat Step 5
to 6 until i=n print "Number is Even."
Step 5 fact=fact*i Else
Step 6 i=i+1 print "Number is Odd."
Step 7 Print fact
Step 4 Stop
Step 8 Stop
Flowchart:
Flowchart:
Start
Start
Read n Read a Number
i = 1
Is
fact = 1
n%2==0
Is Yes No
No
i < = n?
Print Number Print Number
is even is odd
Yes
fact = fact*i
Print fact
Stop
i = i + 1
Stop
Algorithm and Flowchart 97

