Uploaded by Radjel Cosido

ABE 103 Cosido [Lab. Exer. No. 2]

advertisement
NAME: Radjel M.Cosido BSABE 3M2
Central Bicol State University of Agriculture
College of Engineering and Food Science
Department of Agricultural and Biosystems Engineering
ABE 103
Laboratory Exercise 2
Flowchart and Algorithm
Objectives of the Exercise:
The exercise aims to introduce text-based programming to students.
Specifically, the exercise aims for the students to:
a. Able to develop flowchart for computer programs
b. Create algorithms necessary for computational techniques
Design an algorithm and flowchart for the following problems:
1. Find the largest among three different numbers entered by the user.
Algorithm
Step 1: Start
Step 2: Read/ Input num 1, num 2, num 3
Step 3: If (num 1>=num 2) and (num1 >=num 3) then Max= num 1
Step 4: If (num 2>=num 1) and (num 2>=num 3) then Max= num 2
Step 5: If (num 3>=num 1) and (num3>=num 2) then Max=num 3
Step 6: Print Max
Step 7: End
1 of 4
Flowchart
Star t
Read num1, num 2, num 3
False
True
Num1
>num
2
False
Num
2>nu
m3
Print num 2 is the
largest number
False
False
Print num 3 is the
largest number
End
2 of 4
Num 1
> num
3
True
Print num 1 is the
largest number
2. Find all the roots of a quadratic equation ax2+bx+c=0
Algorithm
Step 1. Start
Step 2. Read the coefficients of the equation, a, b and c from the user.
Step 3. Calculate discriminant = (b * b) – (4 * a * c)
Step 4. If discriminant > 0:
4.1: Calculate root1 = (-b + sqrt(discriminant)) / (2 * a)
4.2: Calculate root2 = (-b - sqrt(discriminant)) / (2 * a)
4.3: Display “Roots are real and different”
4.4: Display root1 and root2
Step 5: Else if discriminant = 0:
5.1: Calculate root1 = -b / (2 *a)
5.2: root2 = root1
5.3: Display “Root are real and equal”
5.4: Display root1 and root2
Step 6. Else:
6.1: Calculate real = -b / (2 * a)
6.2: Calculate imaginary = sqrt(-discriminant) / (2 * a)
6.3: Display “Roots are imaginary”
6.4: Display real, “±”, imaginary, “i”
Step 7. End
3 of 4
Flowchart
Start
Read coefficient a, b
and c from the user
v
Discriminant= ( b*b)-(4*a*c)
Discrimi
nant>o?
false
v
vvv
Discrimi
nant=o?
false
Real= -b/(2*a)
v
true
true
Root1=(-b=square root of
discriminant)/(2*a)
Root1=-b/(2*a)
Root2=(-b-square root
of discriminant)/(2*a)
Root1=root2
Imaginary=Square of (discriminant)/(2*a)
Display “
roots are
imaginary”
v
Display “ roots
are real and
different”
Display
root1, root2
Display “
roots are real
and equal”
Display
root1,root2
End
4 of 4
Display real “ +”
imaginary “I”
Display real
“ -” imaginary
“I”
Download