You are on page 1of 54

Flowchart

• A common method for defining the logical


steps of flow within a program by using a
series of symbols to identify the basic Input,
Process and Output (IPO’s) function within a
program.
• A two dimensional representation of an
algorithm; the predefined graphic symbols of
a flowchart are used to indicate the various
operations and the flow of control.
• A diagram representing the logical sequence
in which a combination of steps or operations
is to be performed. It is a blueprint of the
program.
Algorithm
• It is a finite set of functions that specify a
sequence of operations to be carried out in
order to solve a specific problem or class of
problems.
Basic Symbols Used in
Flowcharting
Symbols What it represents

Terminal -Used to signify the beginning and


end of flowchart.

Preparation/ Initialization -Signifies the preparation of data


-Used to select initial conditions
-Used to represent instructions or
group of instructions that will alter or
modify a program’s course of
execution.

Input/ Output -Shows input and output. Data are to


be read into the computer memory
from an input device or data are to be
passed from the memory to an
output device.
Processing -Performs any calculations that are to
be done.

Decision -Signifies any decisions that are to be


done.
-Two alternative execution paths are
possible. The path to be followed is
selected during the execution by
testing whether or not the condition
specified within the outline is
fulfilled.
On-page connector -Shows the entry or exit point of he
flowchart.
-A non-processing symbol used to
connect one part of a flowchart to
another without drawing flow lines.
-Conserves space by keeping related
blocks near one another, reduces the
number of flow lines in complex
programs, and eliminates cross lines
from taking place.

Off-page Connector -Designates entry to or exit from one


page when a flowchart requires more
than one page.

Flow lines Signifies the process that is to be


executed next.
Basic Control
Structure
• Draw a flowchart that will compute and display
the sum and product of two numbers. Write its
equivalent algorithm.
Algorithm:
Step 1. Initialize Sum and Product into O.
Start Step 2. Read in the values of A and B.
Step 3. Compute Sum by adding A and B
then compute Product by multiplying
Sum = 0 A and B.
Product = 0 Step 4. Print the computed value of Sum
and Product.

Enter values
for A and B

Sum = A + B Print Sum,


Product = A * B Product End
• Construct a flowchart that will convert an
inputted number in Fahrenheit to its
equivalent measure in Celsius.
Formula: C = (5/9) x (F-32)
Start Algorithm:
Step 1. Initialize Celsius into 0.
Step 2. Read in the values of Fahrenheit.
Step 3. Compute the value of Celsius.
Celsius = 0 Step 4. Print the computed value of
Celsius.

Input value
for
Fahrenheit

Print
Celsius = (5/9) * (F-32) Celsius End
Operators Commonly
Used in Flowcharting
Arithmetic Operators
Operators Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
Relational Operators
= Equal
> Greater than
< Lesser than
!= Not equal
> Greater than or Equal to
< Less than or Equal to
Logical Operators
&& AND
II OR
! NOT
• DEI Manufacturing Company plans to give a year-
end bonus to each of its employee. Draw a
flowchart which will compute the bonus of an
employee. Consider the following conditions:
If the employee’s monthly salary is less than
2,000 pesos, the bonus is 50% of the salary; for
employees with salaries greater than 2,000
pesos, the bonus is 1,500 pesos.
Print the name and the corresponding bonus for
each employee. Write each equivalent
algorithms.
START Algorithm:
Step 1. Initialize bonus to 0.
Step 2. Read in employee’s name and
Bonus = 0 salary.
Step 3. Test if employee’s salary is less
than 2,000..
Enter Name, Step 4. If salary < 2,000 then
Salary Bonus = salary * 50%
else
Bonus = 1,500
Salary
< Step 5. Print the
Bonus = 1,500 employee’s name
2,000
and bonus.

Bonus = 0.50 * Salary

Print Name,
Bonus END
Start

Bonus = 0

Read Name,
Salary

Salary
<
Bonus = 1,500
2,000

A
Bonus = 0.50 * Salary

Print Name,
Bonus End
Looping
• Do – while –
This structure provides for the repetitive
execution of an operation or routine while
the condition is evaluated before executing
any process statement. As long as the
condition is true, the process is executed,
otherwise, control flows out of the
structure.
F
C

A
• Construct a flowchart that will count from 1 to
10 and print each number counted using the do-
while-repetition structure. Write its equivalent
algorithm. Start

C=0

C End

Algorithm:
Step 1. Initialize the value of C to 0.
C=C+1 Step 2. Test if C is less than 10.
Step 3. If C is less than 10, add 1 to the
value of C, print the value then go
Print C
back to Step 2. However, if C is
greater than 10, stop processing.
Exercise problem.
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.
Remarks(rem) are based on the following criteria: Write
its equivalent algorithms.
4.50 – 5.00 – Outstanding
4.00 – 4.49 – Very Satisfactory
3.50 – 3.99 – Satisfactory
3.00 – 3.49 – Needs Improvement
2.99 below - Poor
Overview of Turbo C Language
History of C Language
 B was developed in the year 1970 by Ken
Thompson
 To augment B’s power Dennis Ritchie invented
and first implemented the C prog. Language at
Bell Laboratories.
 Originally developed under UNIX environment
and became popular 6 years after
 Often called a middle –level language.
Continuation…
 Input, output commands, and special words
are often referred to as reserved words and
are written in lower case only.
 C is case sensitive
 C was initially used for system development
work, programs that make up the operating
system.
Data Types
5 elementary data types
Type Bit width Range
char 8 0 to 255
int 16 -32768 to 32767
float 32 3.41E-38 TO 3.4E+38
double 64 1.7E-308 TO 1.7E+308
void 0 valueless

Type modifier
Signed, unsigned, long, short
Keywords
Keywords in C are reserved words that have a
special meaning. Reserved words are words
“reserved” by the programming language for
expressing various statements and constructs,
thus, these may not be redefined by the
programmer.
List of 32 Keywords / Reserved words as
defined by the ANSI standard
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
VARIABLES,
CONSTANTS,
OPERATORS, AND
EXPRESSIONS
Identifiers Defined
Identifiers are composed of a sequence
of letters, digits and the special character _
(underscore). Avoid using names that are too
short or too long. Limit the identifiers from 8
to 15 characters only.
Variables Defined
Variables are identifiers that can store a
changeable value. These can be different data
types.
Rules for defining or naming identifiers /
variables
1. It must consist only of letters, digits, and underscore.
Example: _duh, num_1 (correct)

2. It should not begin with a digit.


Example: 1name, 3to3 (incorrect)

3. An identifier defined in the C standard library should


not be redefined.
Example: printf, scanf (incorrect)
4. It is case sensitive; meaning uppercase is not equal to the
lowercase.
Example: ans ≠ Ans ≠ aNs ≠ anS ≠ ANs ≠ ANS

5. Do not include embedded blanks.


Example: large num (incorrect)

6. Do not use any of the C-language keywords as your


variable / identifier.

7. Do not call your variable / identifier by the same name as


other functions.
Variable Declaration
All variables must be declared before
they may be used. The general form of
declaration is shown here:

Type variable list;

Example: int i, j, k;
short i, j, k;
Note: *before declaring variable, specify, first
the data type variable/s
* variables must be separated by comma
* all declarations must be terminated by a
semicolon (;)
Two kinds of
variable
Local Variables
“Variables that are declared inside a function are called
local variables. It can only be referenced by statements that
are inside the block in which the variables are declared”.
Example:
#include <stdio.h>
main( )
{
int a, b, c; local variables
________;
________;
________;
}
Global Variables
“Global variables are known throughout the
entire program and may be used by any piece of
code. Global variables are created by declaring them
outside of any function”
Example :
#include <stdio.h>
int a,b,c; global variable
main()
{
;
;
;
}
Constants Defined
Constants are identifiers/variables that can store a
value that cannot be changed during program
execution.

Example : const int count = 100;


Where integer count has a fixed value of 100
Arithmetic, Logical, Relational, and Bitwise
Operators
“ Operator is a symbol that tells the compiler to
perform specific mathematical or logical
manipulations . There are three classes of
operators in C: arithmetic, logical and
relational, and bitwise”.
A. Arithmetic
Operators Action
Operator Addition
Subtraction
+ Multiplication
- Division
* Modulus Divisor
/ Decrement a value
% Increment a value
--
++
B. Relational and Logical Operators
“ In the term relational operator, the word
relational refers to the relationship values can
have with one another. In the term logical
operator, the word logical refers to the ways
these relationships can be connected together
using the rules of formal logic. The key to the
concept of relational and logical operators is
the idea of true or false”.
B.1RelationalOperators
Action
Operator
Greater than
> Greater than or equal to
>= Less than
< Less than or equal to
<= Equal
== Not equal
!=
B.2 Logical Operators
Truth table
Operator
Action
&& true && true = true
true && false = false
AND
false && true = false
false && false= false

II
true II true = true
OR true II false = true
false II true = true
false II false = false

! true = false
I ! false = true
C. Bitwise operator
“ Bitwise operations are the testing, setting or
shifting of the actual bits in a byte or a word, which
corresponds to C’s standard char and int data types
and variants. Bitwise operators cannot be used on
type float, double, long double, void or other more
complex types.”
Operator Action
& AND
I OR
^ Exclusive OR(XOR)
~ One’s complement
>> Shift right
<< Shift left
D. The ? Operator

“? Operator is a very powerful and


convenient operator that can be used to
replace certain statements of the if-then-else
form”.

Example: y = x > 9 ? 100:200

You might also like