Hafta 2
Hafta 2
S4: Print k
S5: End
Example 6.
S1: Start Write an algorithm that will
calculate the roots of a quadratic
S2: Input the coefficients equation
(a, b, c) of the quadratic
ax bx c 0
2
equation
S3: Set d Hint: d = sqrt ( b 2 4ac ), and the
roots are:
S4: Set x1
S5: Set x2 x1 = (–b + d)/2a and
Print A Print B
Decision Structure
IF
Switch
For Loop
While Loops
If control structure has three different types.
If condition then
true alternative
else
false alternative
end
IF–THEN–ELSE STRUCTURE
The algorithm for the flowchart is as follows:
S1: Start
S2: Input A,B
S3: If A>B Y
is
N
S4: Output A A>B
S5: If A<B
S6: Output B Print Print
A B
S7: End
Relational Operators
Relational Operators
Operator Description
> Greater than
< Less than
= Equal to
Greater than or equal to
Less than or equal to
Not equal to
Example 7.
S1: Start
Write an algorithm that
S2: Input VALUE1, VALUE2 reads three values,
determines the largest value
S3: if (VALUE1 > VALUE2) and prints the largest value
S4: Set MAX =VALUE1 with an identifying message.
S1: Start z= X x Y
S2: Input X and Input Y
S3: Set z = X+Y Outout
z
S4: Output z
S5: End
STOP
Example 9. START
Write an algorithm to
determine a student’s final Input
grade and indicate whether it M1,M2,M3,M4
S1: Start N IS Y
N<60
S2: Input M1,M2,M3,M4
S3: Set N=(M1+M2+M3+M4)/4
Output
S4: if (N< 60) then Output
“PASS” “FAIL”
S5: Output “FAIL”
S6: if (N=> 60)
S7: Output “PASS” STOP
S8: End
Example 10.
Write an algorithm that will START
read the two sides of a
rectangle and calculate its
Input
area. W, L
k= L x W
S1: Start
S2: Input W,L Output
S3: Set k= L x W k
S4: Print k
S5: End STOP
Write an algorithm that will
calculate the roots of a quadratic
equation Example 11.
ax 2 bx c 0 START
S3: Set d
Output
S4: Set x1 x1 ,x2
S5: Set x2
S6: Output x1 and x2
STOP
S7: End
Example 12. START
Input
Fınd maximum one to VALUE1,VALUE2
the given 2 different number
Y is
N
S1: Start VALUE1>VALUE2
STOP
Example 13.
F(x) function value is given
according to X value. X is
changing between o and 20
with 0.5 increment. Draw a
flow chart for this calculation.
S1: Start
S2: Input temperature
S3: if temperature<32
S4: set cover tomatoes
S5: if temperature=>32
S6: set uncover tomatoes
S7: End
Example 15.
Find the summation of the numbers
between 1 and 5
S1: Start
S2: Set i=0
S3: while i<5 go to S4
S4: Set i=i+1
S5: while i=>5 go to S6
S6: Output i
S7: End