Lecture 4
Lecture 4
Operators
– Increment and Decrement Operators
– Conditional Operator
– Bitwise Operators
– Special Operators
Control Structure
– if statement
Exercise
1. Write a program which takes marks of five
students as input and computes the
average marks. Print the average mark of
five students.
j =10; Output
i =j++; i = 10 j = 11
Output
j =10;
i=9 j=9
i=--j;
What is the values of i and j?
Conditional Operator
Example: Output
a=5;
X = 10
b=10;
x =(a>b) ? a : b;
What will be the value of x??
Bitwise Operators
Operator Meaning
Flow Charts
– Flow Charts are maps or graphical representations of a
process.
– Steps in a process are shown with symbolic shapes, and
the flow of the process is indicated with arrows
connecting the symbols
Symbols in Flowchart
START , END
INPUT
DECISION
CONNECTOR
CONNECTOR
Example Flow Chart
START Flow chart to find
whether the the marks of
Marks = 50
a student is above avg or
Avg = 45 below avg
NO
Marks > avg Print below Avg
YES
END
Example on flowchart
INPUT bs
YES is NO
bs < 1500
Gs = bs + hra + da
PRINT STOP
GS
Control Structures
It controls the flow of execution in a
program.
It enables you to combine individual
instructions into a single logical unit with
one entry and one exit point.
Control Structure
Sequential Control Structure
– It’s a sequential flow of execution of
instructions.
Selection Control Structure
– This control structure chooses among
alternative program statements.
Repetition Control Structure
– This control structure repeats a group of
program statements till it satisfies some
condition.
if Statement
F
if (condition) condition
{
T
statement-block;
} Statement -block
next-statement;
Similar to BR instruction in LC-3
if (x <= 10) {
compound statement;
y = x * x + 5;
both executed if x <= 10
z = (2 * y) / 3;
}
if (x = 2)
y = 5; always true,
so y = 5 is always executed!