Page 45 - iprime_V2.2_class8
P. 45
Example 3: Flowchart to add the first 100 Example 4: Flowchart to find the greatest of 3
natural numbers. numbers.
Start Start
Sum = 0
Read the three numbers A,B,C
N = 0
No Is Yes
N = N + 1
A>B?
Sum = Sum + N Is No No Is
B>C? A>C?
Is
N >= 100? Yes Yes
No
Print B Print C Print A
Yes
Print Sum
Stop
Stop
SOLVING PROBLEMS USING ALGORITHMS AND
FLOWCHARTS
Example 1: Write an algorithm and draw a flowchart to calculate the factorial of a number.
Algorithm
Step 1 Start
Step 2 Read the number n
Step 3 Initialise i=1, fact=1
Step 4 Check if i < = n then repeat step 5 & 6 until i=n
Step 5 fact=fact*i
Step 6 i=i+1
Step 7 Print fact
Step 8 Stop
Algorithm and Flowcharts 43

