Week 2
Week 2
COURSE OUTLINE
Overview:
Content
• Operators
• Flowchart with decision making
• If statement in flowchart
• If else statement in flowchart
Objectives:
Each chapter in this module contains a major lesson involving the use of Flowchart and its purpose.
The units are characterized by continuity, and are arranged in such a manner that the present unit is
related to the next unit. For this reason, you are advised to read this module. After each unit, there are
exercises to be given. Submission of task given will be every Monday during your scheduled class hour.
OPERATORS
An operator is a symbol that tells the compiler to perform specific mathematical or logical
functions. C language is rich in built-in operators and provides the following types of operators:
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Assignment Operators
• Misc. Operators
Arithmetic Operators
The following table shows all the arithmetic operators supported by the C language. Assume
variable A holds 10 and variable B holds 20, then:
Relational Operators
The following table shows all the relational operators supported by C. Assume variable A holds
10 and variable B holds 20, then:
Logical Operators
Following table shows all the logical operators supported by C language. Assume variable A
holds 1 and variable B holds 0, then:
Assignment Operators
The following tables lists the assignment operators supported by the C language:
Besides the operators discussed above, there are a few other important operators including
sizeof and ? : supported by the C Language.
Operators Precedence in C
Operator precedence determines the grouping of terms in an expression and decides how an
expression is evaluated. Certain operators have higher precedence than others; for example, the
multiplication operator has a higher precedence than the addition operator.
For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher
precedence than +, so it first gets multiplied with 3*2 and then adds into 7.
Here, operators with the highest precedence appear at the top of the table, those with the lowest
appear at the bottom. Within an expression, higher precedence operators will be evaluated first.
Decision-making structures require that the programmer specifies one or more conditions to be
evaluated or tested by the program, along with a statement or statements to be executed if the
condition is determined to be true, and optionally, other statements to be executed if the condition is
determined to be false.
Shown below is the general form of a typical decision-making structure found in most of the
programming languages:
C programming language assumes any non-zero and non-null values as true, and if it is either zero
or null, then it is assumed as false value.
STATEMENT DESCRIPTION
if statement An if statement consists of a Boolean expression
followed by one or more statements.
if...else statement An if statement can be followed by an optional
else statement, which executes when the
Boolean expression is false.
nested if statements You can use one if or else if statement inside
another if or else if statement(s).
switch statement A switch statement allows a variable to be tested
for equality against a list of values.
nested switch statements You can use one switch statement inside another
switch statement(s).
If statement flowchart
Example:
1. Draw a flowchart that will check if variable a
is less than 20.
If else statement Flowchart
An if statement can be followed by an optional else statement, which executes when the Boolean
expression is false.
Example:
1. Draw a flowchart that will print “Young” if the age is less than or equal to 19, else print
“Old”.
2. Draw a flowchart that will input a number print “I love Philippines” if the number if below 30,
else print “I am hungry”.
When using if…else if…else statements, there are few points to keep in mind:
• An if can have zero or one else's and it must come after any else if's.
• An if can have zero to many else if's and they must come before the else.
• Once an else if succeeds, none of the remaining else if's or else's will be tested.
Example
1. Draw a flowchart that will print “Like” if the number is equal to 5, Print “Share” if the number is
equal to 6, else print Subscribe.
2. Draw a flowchart that will find the largest among three numbers.