Professional Documents
Culture Documents
UNIT 5 Logical Structures and Basic Instructions
UNIT 5 Logical Structures and Basic Instructions
Sequence structure
Selection structure
Repetition or iteration structure
Compiles and run program
5.1.1 SEQUENCE STRUCTURE
Example:
x=5 (SI)
y = 10 (S2)
Total = x*y (S3)
cout<< “\n"<< "Total =" <<Total< \n"; (S4)
5.1.2 SELECTION STRUCTURE
if statement
if-else statement
Switch statement.
A. IF STATEMENT
The basic form of the if statement is:
If (expression) statement
Example 5.2:
The output:
20 is greater then 5
B. IF-ELSE STATEMENT
The basic form of the if-else statement is:
if (expression) statement_1, else statement_2
Example 5.3:
Example 5.4:
NESTED IF – ELSE STATEMENT
The basic form of the if-else, statement is:
Example 5.5:
C. SWITCH STATEMENT
5.1.3 REPETITION (OR
ITERATION) STRUCTURE
Program output:
1 4 9 16 25 36 49 64 81 100
COMPILES AND RUN PROGRAM
SEKIAN
TERIMA KASIH