Flowchart
Flowchart
EXAMPLES
Read
A
Read
B
Read
N1
Read
N2
D = N1 – N2
Read
T
1 T < 10
0
1 0
T < 25
V = (60/10)*T
V = 60
V=60-(60/10)*(T-25)
Print V
Stop
2005 Hakan Uraz - BM111 9
FLOWCHART EXAMPLES
• Example 4: Work on the algorithm and
flowchart which examines an ABC triangle
according to its sides whose sides are
entered as input.
• Variables:
– A: Length of the first side
– B: Length of the second side
– C: Length of the third side
0 A=B
1
0 A=C
1
0 B=C
1
B=C
1
0
“İkizkenar”
“Çeşitkenar” “Eşkenar”
Stop
2005 Hakan Uraz - BM111 12
FLOWCHART EXAMPLES
• Example 5: Work on the algorithm and the
flowchart of the problem of calculating the
roots of the equation Ax2 + Bx + C = 0
• Variables:
– A: Coefficient of X2
– B: Coefficient of X
– C: Constant term
– delta: Discriminant of the equation
– X1: First root of the equation
– X2: Second root of the equation
2005 Hakan Uraz - BM111 13
FLOWCHART EXAMPLES
• Algorithm:
– Step 1: Start
– Step 2: Input A, B and C
– Step 3: Calculate delta = B2 – 4AC
– Step 4: If delta<0 go to step 6, otherwise go to 5
– Step 5: If delta>0 go to step 7, otherwise go to 8
– Step 6: Output “complex roots”. Go to step 9
– Step 7: Output “real roots”. Go to step 9
– Step 8: Output “equal roots”. Go to step 9
– Step 9: Calculate X1=(-b+ delta)/(2A)
– Step 10: Calculate X2=(-b- delta)/(2A)
– Step 11: Output X1
– Step 12: Output X2
– Step 13: Stop
2005 Hakan Uraz - BM111 14
FLOWCHART EXAMPLES
Start Read Delta=B^2-4*A*C
A,B,C
1 Delta<0
0
“Real roots”
“Equal roots”
X1=(-b+ delta)/(2*A)
X2=(-b- delta)/(2*A)
Input
1 X>=10
0
Age A Print “Age Error”
A = 18
0 A = 19
0 A = 20
1 1 1
S18 = S18 + 1 S19 = S19 + 1 S20 = S20 + 1
X = X +1
1 counter<N
Print Nfac
counter = counter + 1
Stop