introducing block scheme programming march 17. algorithm / flow chart an algorithm or a flowchart is...
TRANSCRIPT
Introducing block scheme programming
March 17
2
Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for
solving a particular problem, independently of the programming language.
A general plan for solving problems consist of Write the specification of the problem to be solved i.e. inputs,
outputs Draw flowchart or write algorithm Convert flowchart (algorithm) into program code Compile the program into object code Execute the program
3
Flow chart basic symbols
Computations
Input / Output
Decision
Start / stop
Connector
Flow of control
4
Adding the numbers
start
read A, B, C
S = A + B + C
output S
stop
5
Larger of two numbers
start
read X, Y
output X
stop
X > Y ?
output Y
stop
yes no
6
Larger of three numbers
start
read X, Y, Z
stop
X > Y ?
stop
yes no
max > Z ?
Output max Output z
yes no
Max = X Max = Y
7
start
read N
stop
Count > N ?
output sum
no yes
sum = sum + count * count
sum = 0count = 1
count = count + 1
Sum = 12 + 22 + 32 + … + N2
8
start
read N
stop
Count > N ?
output sum
no yes
sum = sum + count * (count + 1)
sum = 0count = 1
count = count + 1
sum = 1 * 2 + 2 * 3 + 3 * 4 + … + N* (N +1)
9
start
read N
stop
count > N ?
output sum
no yes
prod = prod * count
prod = 1count = 1
count = count + 1
Computing factorial
10
start
Read X, N
stop
count > N ?
output sum
noyes
sum = prod * countterm = term * X / count
term = 1prod = 1count = 1
count = count + 1
Computing ex series up to N terms
Use Taylor expansion to represent ex up to N terms.
11
start
Read X, N
stop
term < .0001 ?
output sum
noyes
sum = prod * countterm = term * X / count
term = 1prod = 1count = 1
count = count + 1
Computing ex series up to 4 decimal places
Use Taylor expansion to represent ex up to 4 decimal places.
12
Do you it yourself Draw a block scheme for the algorithm that finds roots of
quadratic equations ax2 + bx + c = 0
13
Homework Draw a flowchart for the following algorithms
1. Find whether a number is prime or not.2. Find sin(x), using the following series
Hint: see problem on slides 10 and 11
…