a step-by-step procedure for solving a problem in a finite number of steps

18
www.btechsmartclass.blogspot.com Flow Charts & Algorithms

Upload: phoebe-neal

Post on 03-Jan-2016

221 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: A step-by-step procedure for solving a problem in a finite number of steps

www.btechsmartclass.blogspot.com

Flow Charts & Algorithms

Page 3: A step-by-step procedure for solving a problem in a finite number of steps

Problem Statement:

Algorithm Example

Find the sum of natural numbers from 0 to 50

START

IF N <= 50 THEN GOTO Step 4PRINT sumSTOP

Step 1:Step 2:Step 3:Step 4:Step 5:Step 6:Step 7:Step 8:

sum 0N 1sum sum + N N N + 1

Page 4: A step-by-step procedure for solving a problem in a finite number of steps

Problem Statement:

Algorithm Assignment

Find the sum of any TWO numbers

Problem Statement:Check whether a number given by user is EVEN or ODD

Problem Statement:Find the largest of THREE numbers

Page 6: A step-by-step procedure for solving a problem in a finite number of steps

Terminal Symbol: indicates the starting or stopping point in the logic.

Input/Output Symbol:Represents an input or output process in an algorithm

Process Symbol:Represents any computational step or processing

Decision Symbol:Represents a decision in the logic involving the Comparison Of two values.

Flow Lines

Basic symbols

Page 7: A step-by-step procedure for solving a problem in a finite number of steps

Basic symbols

Page 8: A step-by-step procedure for solving a problem in a finite number of steps

www.btechsmartclass.blogspot.com

Three Basic Control Structures

Page 9: A step-by-step procedure for solving a problem in a finite number of steps

Statemement a

Statemement b

Statemement c

SequenceSequence is a default control structure. Instructions are executed one after another

Page 10: A step-by-step procedure for solving a problem in a finite number of steps

Selection structure test the condition and then executes one sequence of statements instead of another, depending on whether the condition is true or false

Selection

Page 11: A step-by-step procedure for solving a problem in a finite number of steps

Condition p?

Statemement a Statemement b

T F

Selection

Page 12: A step-by-step procedure for solving a problem in a finite number of steps

Condition p?

Statemement a

T

F

Selection

Page 13: A step-by-step procedure for solving a problem in a finite number of steps

Repetition structure specifies the repetition of an action while some condition remains true. When the conditions of the control statement have been met and control passes to the next statement beyond the repetition structure

Repetition

Page 14: A step-by-step procedure for solving a problem in a finite number of steps

Condition p?

Statemement block

T

F

Repetition

Page 15: A step-by-step procedure for solving a problem in a finite number of steps

MAX VALUE1

Print“The largest value is”,

MAX

STOP

Y N

START

InputVALUE1,VALUE2

MAX VALUE2

isVALUE1>VALUE2

Example

Page 17: A step-by-step procedure for solving a problem in a finite number of steps

Example :largest of three numbers

Page 18: A step-by-step procedure for solving a problem in a finite number of steps

Assignment questions

1.Check a given number is even or not

2.Display even numbers between 10&100