Turbo C Manual Chapter 2 Algo N Flowchart Module 2
Turbo C Manual Chapter 2 Algo N Flowchart Module 2
LANGUAGE
MODULE II
ALGORITHM AND FLOWCHART
LEARNING OBJECTIVES
At the end of this chapter, the student should
be able to: INTRODUCTION
1|Page
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
LESSON 1
ALGORITHM
A. Algorithm Defined
B. Properties of Algorithm
4. Input and Output - defined the unknowns of the problem is specified and with the
expected outcome.
2|Page
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
1. Pseudocode
D. Examples
Pseudocode:
if average is below 75
Print “FAILED”
else
Print “PASSED”
3|Page
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
Detailed Algorithm
Print “FAILED”
else
Print “PASSED”
endif
Pseudocode:
Detailed Algorithm
4|Page
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
CONCEPT REVIEW
I. Fill in the blanks Fill in the blanks with the correct answer.
A. Properties of Algorithm
1.
2.
3.
4.
5.
6.
1.
2.
5|Page
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
1. Write an algorithm that will compute the average of five input quizzes, and then
display the result.
6|Page
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
4. Write an algorithm that will prompt for and receive 18 examination scores from a
mathematics test, compute the class average, and display all the scores and the
class average.
7|Page
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
LESSON 2
FLOWCHART
A. Flowchart Defined
B. Flowchart Symbols
Only a few symbols are needed to indicate the necessary operations in a flowchart.
These symbols have been standardized by the American National Standards
Institute (ANSI).
1. Processing
8|Page
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
2. Flow lines
Flow lines with arrowheads are used to indicate the flow of operation, that is, the
exact sequence in which the instructions are to be executed. The normal flow of
flowchart is from top to bottom and left to right. Arrowheads are required only when
the normal top to bottom flow is not to be followed.
3. Decision
The decision symbol is used in a flowchart to indicate a point at which a decision has
to be made and a branch to one of two or more alternative points is possible.
4. Connector
If a flowchart becomes very long, the flow lines start crisscrossing at many places
that causes confusion and reduces the clarity of the flowchart. Moreover, there are
instances when a flowchart becomes too long to fit in a single page and the use of
flow lines becomes impossible. Thus, whenever a flowchart becomes too complex
that the number and direction of flow lines is confusing or it spreads over more than
one page, it is useful to utilize the connector symbol as a substitute for flow lines.
This symbol represents an entry from, or an exit to another part of the flowchart. A
connector symbol is represented by a circle and a letter or digit is placed within the
circle to indicate the link. A pair of identically labeled connector symbols is
commonly used to indicate a continued flow when the use of a line is confusing.
9|Page
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
10 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
C. Flowcharting Guidelines
or
e. Only one flow line should enter a decision symbol, but two or three flow lines,
one for each possible answer, should leave the decision symbol.
12 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
The essentials of what is done can easily be lost in the technical details of
how it is done.
Examples:
1. Draw a flowchart that will accept and display a number. Write its equivalent
pseudocode.
13 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
BEGIN
Algorithm
2. Draw a flowchartRead A will compute and display the sum and product of two
that
numbers. Write its equivalent pseudocode. Step 1. Read in the value of A
BEGIN Algorithm
Step 2. Print the value of A.
Print A
S=0
P=0 Step 1. Initialize sum(S) and
END
product(P) into 0.
P=0
Step 2. Read in the values of A
Read A, B
and B.
END
14 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
3. Draw a flowchart that will read the two sides of a rectangle calculate and print its
area. Write its equivalent pseudocode. Formula: Area = Length x Width.
BEGIN Algorithm
A=LxW
Print
END
A
END
15 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
2. Selection - Once the condition is evaluated, the control flows into one of two
paths. Once the conditional execution is finished, the flows rejoin before leaving the
structure. As an alternative, the "Question" could be replaced with a Boolean
expression and the branches labelled "TRUE" and "FALSE".
A. Arithmetic Operators
Operators Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
16 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
B. Relational Operators
Operators Meaning
= Equal
C. Logical Operators
Operator Meaning
&& AND
II OR
! NOT
Examples:
1. Draw a flowchart that will input values for x and y. Compare two values inputted
and print which of the values is higher including the remark “Higher”. Write its
equivalent pseudocode.
Algorithm
Step 3. IfWork
x is greater than y, x is higher. However, if x is 17 | P a g e
Instructional Book
less than y, y is higher.
INTRODUCTION TO C
LANGUAGE
2. Draw a flowchart that will determine the student’s final grade and indicate weather
BEGIN
it is passing or failing. The final grade is calculated as the average of four marks.
Input
Algorithm x, y
else 18 | P a g e
Instructional Work Book
Print “PASS”
INTRODUCTION TO C
LANGUAGE
BEGIN
Grade=0
Input
M1,M2,M3,M4
Grade=(M1+M2+M3+M4)/4
F IS GRADE<75 T
Print Print
“Passed” ”Failed”
19 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
Algorithm
Bonus = salary * 25 %
Else
Bonus = 3,000
BEGIN
bonus=0
Read Name,
Salary
Salary F
< 10,000 Bonus = 3,000
T
Bonus = 0.50*Salary
Print Name,
Bonus
END
20 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
4. Construct a flowchart that will accept the evaluation score of a faculty and
determine its equivalent remarks. Print the name of the faculty and the remarks
obtained. Write the equivalent pseudocode. Remarks are based on the following
criteria:
Algorithm
Step 6. If the score is greater than or equal to 4.00, Rem is “Very Satisfactory”.
However, if the score is less than 4.00, do step 7.
Step 10. If the score is greater than or equal to 3.00, Rem is “Needs
Improvement”. However, if the score is less than 3.00, Rem is “Poor”.
21 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
BEGIN
Rem = “ “
Read Name,
Score
Score T
> 4.50 Rem=”Outstanding” A
Score T
> 4.00 Rem=”Very Satisfactory” A
Score T
> 3.50 Rem=”Satisfactory” A
22 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
Score T
> 3.00 Rem=”Needs Improvement” A
F
Rem=”Poor”
A
Print Name,
Rem
END
23 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
Looping
Used when it is desired to make the same calculation of more than one set of
data. It consists of repeating a program, or a section of program and substituting
new data for each repetition.
Counter
Initialization
24 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
Before the logic flow gets out of a loop, a loop terminating condition must first
be satisfied.
Incrementation
Often each loop is executed, 1 is added to the counter. Thus counter reflects
the number of times the operation has been performed.
Examples:
1. Construct a flowchart that will count from 1 to 10 and print each number counted
using the looping structure. Write the equivalent pseudocode.
Algorithm
Step 3. If N is less than 10, add 1 to the value of N, print the value then
go back to step 2. However, if N is greater than 10, stop
processing.
25 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
BEGIN
2. The initial value of the radius of a circle is equal to 1 unit and each succeeding
radius is 1 unit greater than the value before it. Draw a flowchart to compute the
area of a circle starting with radius=1 up to radius = 5, then print each radius and the
corresponding area of a circle. N=0
Formula: area = pi x r2
N<10 F
END
Algorithm T
BEGIN
Pi=3.1416
r=1
area=pi * r *r
Print r, area
r=r+1
F
T
r<5 END
27 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
Algorithm
Step 1:Base = 2, Power = 4, Counter =1, Product=2
Step 2:While Counter < Power
Repeat Steps 2- 5
Step 3: Product = Product * Base
Step 4: Counter = Counter +1
Step 5: Print Product
BEGIN
Base=2
Power=4
Product=2
Counter=1
Y
Print
Product =Product * Base Product
Counter= Counter + 1
END
28 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
CONCEPT REVIEW
I. Fill in the blanks. Fill in the blanks with the correct answer.
1.
2.
3.
4.
5.
29 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
1. Draw a flowchart that computes the average of three input quizzes, and then
display the result.
30 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
2. Draw a flowchart that converts the input Fahrenheit degree into its Celsius degree
equivalent. Use the formula: C= (5/9)*F-32. Print the computed value of Celsius.
31 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
32 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
4. Draw a flowchart that converts the input Celsius degree into its equivalent
Fahrenheit degree. Use the formula: F= (9/5) * C+32. Print the computed value of
Fahrenheit.
33 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
5. Draw a flowchart that will compute for the midterm grade of a student. The
midterm grade is equal to one-third of the minor exam and two-thirds of the midterm
exam. Print the midterm grade.
34 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
6. Read two records in a computer. The first record will contain unit price and the
second record will contain quantity. Draw a flowchart that will compute and display
the amount by multiplying unit price and quantity.
35 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
36 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
8. Draw a flowchart that will determine and display the largest number among 3
numbers being inputted.
37 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
9. Construct a flowchart that asks for the amount purchased by the customer. If the
customer purchases more than 2,000 then a 5% discount is given. Display the net
amount to be paid by the customer.
38 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
10. Draw a flowchart that will generate the sum and product of 20 input numbers.
39 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
11. Draw a flowchart that will input 10 integers. Output the number of negative
values and the sum of positive numbers.
40 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
12. Draw a flowchart that accepts a number in kilowatts then display the equivalent
number in watts. Hint: 1 watt = 0.0001 kilowatt.
41 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
13. Given two numbers A and B, draw a flowchart to determine the difference
between A and B and the value of X. If A – B is negative, X= A + B; if A – B is zero,
X = 2A + 2B; and if A – B is positive, X = A * B. Print the values of A, B and X.
42 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
SKILLS REVIEW
14. Write an algorithm and draw a flowchart to a) read an employee name (NAME),
overtime hours worked (OVERTIME), hours absent (ABSENT) and b) determine the
bonus payment (PAYMENT). Display the employee name and bonus payment.
Bonus Schedule
OVERTIME – (2/3)*ABSENT Bonus Paid
>40 hours $50
10 hours $10
43 | P a g e
Instructional Work Book
INTRODUCTION TO C
LANGUAGE
44 | P a g e
Instructional Work Book