Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

ES084: INTRODUCTION TO C PROGRAMMING SECOND SEM AY 23-24

CONTROL FLOW 3. The usual direction of the flow of a procedure or


system is from left to right or top to bottom.
Control Structures 4. Only one flow line should come out from a
 specify the sequence of execution of a group of process symbol.
statements 5. Only one flow line should enter a decision
 3 Types: symbol, but 2 or more flow lines, one for each
1. Sequential possible answer, should leave the decision symbol.
2. Conditional 6. If flowchart becomes complex, it is better to use
3. Iterative connector symbols to reduce the number of flow
lines. Avoid the intersection of flow lines.
Sequential Logic Structure 7. Ensure that flowchart has a logical start and end.
 The oldest logic structure 8. It is useful to test the validity of the flowchart by
 The most used logic structure passing through it with a simple test data.
 The easiest structure to understand
 Is one statement after another statement, after Advantages of Flowchart
another statement, after another statement, etc. These are a better way of
1. Communication communicating the logic of a
FLOWCHART system to all concerned.
With the help of flowchart,
Flowchart 2. Effective
problem can be analyzed in
 A diagrammatic representation that illustrates Analysis
more effective way.
the sequence of operations to be performed to
get the solution of a problem 3. Proper It serves as a good program
 Generally drawn in the early stages of formulating Documentation documentation.
computer solutions It acts as a guide or blueprint
 Facilitate communication between programmers 4. Efficient during the system analysis
and business people Coding and program development
 Documentation of a complex program phase.
5. Proper It helps in debugging
Flowcharting Debugging process.
 A technique of showing logical flow of data in
 Maintenance becomes
pictorial form and integration of programming steps
6. Efficient easy with.
for solving a given problem
Program  It helps the programmer to
Maintenance put efforts more efficiently
Program Flowchart
on that part.
 Flowchart
 A means of visually presenting the flow of
Limitations of Flowcharts
data through an information processing
1. Complex Logic
systems, the operations performed within
 Sometimes the logic is quite complicated, which
the system and the sequence in which they
makes flowchart becomes complex and
are performed
clumsy.
 Describes what operations (and in what
2. Alteration and Modifications
sequence) are required to solve a given problem
 If alterations are required, the flowchart may
 Can be likened to the blueprint of a building
require re-drawing completely.
 Similarly, a programmer prefers to draw a
3. Reproduction
flowchart prior to writing a computer
 Flowchart symbols cannot be typed, thus,
program.
reproduction of flowchart becomes a problem.
 The flowchart is drawn according to defined rules
4. The essentials of what is done can easily be lost in
and using standard flowchart symbols
the technical details of how it is done.
prescribed by the American National Standard
Institute, Inc.

Guidelines in Flowcharting
1. In drawing a proper flowchart, all necessary
requirements should be listed in logical order.
2. Flowchart should be clear, neat and easy to
follow.
Algorithms and Flowcharting Most Commonly Used Symbol

FLOWCHART SYMBOLS

1. Terminal Symbol used to designate the


beginning and end of a
program

2. Input Symbol represents an instruction to an


Flowchart (Applications)
or input device
1. Sequential Structure
 A series of processes that follow in order
used to represent a group of  Ex. To wash your hair
3. Processing program instructions that 1. Wet hair
Symbol perform a processing 2. Apply shampoo
function or activity such as 3. Rinse
mathematical operations or
logical comparisons

4. Output Symbol represents an instruction to an


output device
or

denotes a point in the program 2. Decision Making Structure


5. Decision Symbol where more than one path  A condition exists that may change the order
can be taken or used to or types of processes to be followed
designate a decision making  Ex. IF the light is red THEN I will stop
process OTHERWISE I will go.

 used to show reading order


6. Flow lines and or sequence in which
Arrowheads flowchart symbols are to be
lead
 show the direction of
processing of data flows

7. On-page 3. Looping Structure


Connector  non-processing symbol  Often, we might wish to perform the same
 used to connect one part of set of processes a number of times, we can
the flowchart to another perform a loop and do the same set of
without drawing flow lines actions over and over until a STOPPING
within page condition occurs
 Failure to provide a STOP condition will
cause the process to go into an INFINITE
 non-processing symbol LOOP
8. Off-page
 used to connect one part of  Example of a LOOP
Connector
the flowchart to another  Display the word ‘SCHOOL’ on the
without drawing flow lines screen 7 times
not within the same page

9. Predetermined
 used as a subroutine symbol
Symbol
 inner procedure needs to be
repeated several times

10. Preparation/
Initialization
Symbol
Sequential/Linear Flowchart

Sample Flowchart
System Flowchart Symbols Detailed Flowchart
 Provides a detailed picture of a process by
mapping all of the steps and activities that occur
in the process.
 This type of flowchart indicates the steps or
activities of a process and includes such as
o decision points
o waiting periods
o tasks that frequently must be redone
(rework) and
o feedback loops
System Flowchart Example: Car Repair Garage  Useful for examining areas of the process in detail
and for looking for problems or areas of
inefficiency
 For example, the Detailed Flowchart of Patient
Registration reveals the delays that result when
the record clerk and clinical officer are not available
to assist clients.

SAMPLE PROBLEMS
Sample Problems
1. Make a flowchart that will input the length and width
of a rectangle. Output the perimeter.

2. Make a flowchart that will compute for the area of a


circle given a radius of 9 cm.

3. Make a flowchart that will ask the user to input the


OTHER TYPES OF FLOWCHARTS radius of a circle. Compute for the area of a circle
and output it.
High-Level Flowchart
 Also called first-level or top-down 4. Make a flowchart that will input 2 integers and will
 Shows the major steps in a process output the sum, difference, product and quotient of
 Illustrates a "birds-eye view" of a process, such the 2 integers.
as the example in the figure entitled High-Level
Flowchart of Prenatal Care 5. A certain store sells softdrinks for P 6.00 and
 Can also include the intermediate outputs of each sandwiches for P 6.50. Draw the flowchart to input
step (the product or service produced), and the the number of softdrinks and sandwiches bought and
sub-steps involved output the bill.
 Such a flowchart offers a basic picture of the
process and identifies the changes taking place 5-1. A certain store sells softdrinks for P 6.00 and
within the process. sandwiches for P 6.50. Draw the flowchart to input
 It is significantly useful for identifying the number of softdrinks and sandwiches bought
appropriate team members (those who are and output the bill. Assume that your program will
involved in the process) and for developing ask the buyer to input amount to pay. Output the
indicators for monitoring the process because change to given to the buyer.
of its focus on intermediate outputs.
 Most processes can be adequately portrayed in 4 6. Make a flowchart that will prompt the user to input
or 5 boxes that represent the major steps or the base and the height of a triangle. Output the
activities of the process. computed area of a triangle.
o In fact, it is a good idea to use only a few
boxes, because doing so forces one to 7. Make a flowchart that will input a measurement in
consider the most important steps. meters and output the equivalent measurement in
o Other steps are usually sub-steps of the inches.
more important ones.
8. Make a flowchart that will input the area of a circle.
Determine the diameter of the circle.
9. A salesman in XYZ Company is selling toothpaste RESOURCES
for P89.75 each and tooth powder for P155.95 each.
The salesman will have a 10% commission on the Instructional Resources Textbook
sale of toothpaste and 20% commission on tooth References:
powder. Draw a flowchart and a C Program to input  005.133/B789/2013
the name of the salesman, the number of toothpaste Bronson, Gary J. C++ Programming: Principles
and tooth powder he sells. Output the name of the and Practices for Scientists and Engineers.
salesman, the total sale and the total commission he Cengage Learning, 2013.
earned.  005.133/F769/2011
Forouzan, Behrouz A. Foundations of C
10. Make a flowchart and a C Program that will compute Programming. Cengage Learning, 2011.
for the distance between 2 points A and B. The user  005.133/M295/2011
is asked to input the values of points A (x1, y1) and Malik, D.S. C++ Programming: Problem
B (x2, y2). Output the following: Analysis to Program Design. Cengage
a. distance between the 2 points Learning, 2011.
b. slope of the line  005.133/Sch644/2011
Scholl, T., Nugent, G. C++ Programming
11. Max wants to borrow P50, 500.00 in a bank to put Problem Analysis to Program Design (Lab
up a small business. The bank gives a rate of 9.5 Manual). Cengage Learning, 2011
percent for a 6 year period of time. Compute for the  005.133/V74/2008
interest that Max will pay after 6 years? Output the Vine, Micheal A. C Programming for the
computed interest. Draw the flowchart and make a C Absolute Beginner, 2008
Program.
Internet Sources:
12. Make a flowchart to input a radius and will compute  www.course.com
for the area and volume of a sphere (surface). Output  www.thomsonlearning.com
the computed area and volume.
 www.tutorialspoint.com/cprogramming/
Area = 4 × pi × radius2
 www.cprogramming.com/tutorial/c-tutorial.html
Volume= 3/4 × pi × radius3
 www.iu.hio.no/~mark/CTutorial/CTutorial.html
 http://fresh2refresh.com/c-tutorial-for-beginners
13. Make a flowchart and a C program to input 2
integers. If the 1st integer is greater than the 2 nd
integer, compute the sum of the 2 integers, otherwise
compute the product. Output the sum or product of
the 2 integers.

14. Any customer whose total PURCHASE is at least


P1000 will be given a 10% discount. Make a
flowchart that would input the customer’s
PURCHASE and output his net BILL.

You might also like