Intro 1
Intro 1
Intro 1
FLOWCHARTS
START
Print Print
“PASS” “FAIL”
STOP
EXAMPLE 2
Example 2: Write an algorithm and draw a
flowchart to convert the length in feet to
centimeter.
General Steps
We need length in feet
Multiply it with 30
Algorithm Flowchart
Step 1: Input Lfeet START
Lcent Lfeet x 30
Print
Lcent
STOP
EXAMPLE 3
Write an algorithm and draw a flowchart that
will read the three numbers and perform sum
ALxW
Print
A
STOP
EXAMPLE 5
Write an algorithm that reads two values,
determines the largest value and prints the
largest value with an identifying message.
ALGORITHM
Step 1: Input VALUE1, VALUE2
Step 2: if (VALUE1 > VALUE2) then
MAX VALUE1
else
MAX VALUE2
endif
Step 3: Print “The largest value is”, MAX
START
Input
VALUE1,VALUE2
Y N
is
VALUE1>
VALUE2
Print
“The largest value is”,
MAX
STOP
Write an algorithm and draw a
flowchart that will calculate the
roots of a quadratic equation
Algorithm: START
Step 1: Input a, b, c
Step 2: d sqrt ( b^2 – 4 ac) Input
Step 3: x1 (–b + d) / (2 x a) a, b, c
Step 4: x2 (–b – d) / (2 x a)
Step 5: Print x1, x2 d sqrt(b x b – 4 x a x c)
x1 (–b + d) / (2 x a)
X2 (–b – d) / (2 x a)
Print
x1,x2
STOP
DECISION STRUCTURES
The expression A>B is a logical expression
it describes a condition we want to test
if A>B is true (if A is greater than B)
we take the action on left
print the value of A
if A>B is false (if A is not greater than
B) we take the action on right
print the value of B
IF–THEN–ELSE STRUCTURE
The structure is as follows:
If (condition) then
true alternative
else
false alternative
endif
IF–THEN–ELSE STRUCTURE
The algorithm for the flowchart is as follows:
If (A>B) then
print A
else
print B Y is N
endif A>B
Print Print
A B
SAMPLE QUES ON ALGORITHMS/FLOWCHART
ASSIGN -1