introducing block scheme programming march 17. algorithm / flow chart an algorithm or a flowchart is...

13
Introducing block scheme programming March 17

Upload: roy-hall

Post on 29-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular

Introducing block scheme programming

March 17

Page 2: Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular

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

Page 3: Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular

3

Flow chart basic symbols

Computations

Input / Output

Decision

Start / stop

Connector

Flow of control

Page 4: Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular

4

Adding the numbers

start

read A, B, C

S = A + B + C

output S

stop

Page 5: Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular

5

Larger of two numbers

start

read X, Y

output X

stop

X > Y ?

output Y

stop

yes no

Page 6: Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular

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

Page 7: Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular

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

Page 8: Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular

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)

Page 9: Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular

9

start

read N

stop

count > N ?

output sum

no yes

prod = prod * count

prod = 1count = 1

count = count + 1

Computing factorial

Page 10: Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular

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.

Page 11: Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular

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.

Page 12: Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular

12

Do you it yourself Draw a block scheme for the algorithm that finds roots of

quadratic equations ax2 + bx + c = 0

Page 13: Introducing block scheme programming March 17. Algorithm / Flow chart An algorithm or a flowchart is a step-by-step procedure for solving a particular

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