Lab 3 (Saha)
Lab 3 (Saha)
PRACTICAL TASK : PT 3
TITLE : CONTROL STATEMENT (SELECTION STATEMENT)
1.0 Objectives
2.0 Introduction
Control statements control the flow of execution of the statements of a program. The various types of
control statements in C language are as under: -
a. Sequential
b. Conditional
c. Iteration
In conditional control, the execution of statements depends upon the condition-test. If the condition
evaluates to true, then a set of statements is executed otherwise another set of statements is followed.
This control is also called Decision Control because it helps in making decision about which set of
statements is to be executed. Decision control structure in C can be implemented by using: -
a. If statement
b. If-else statement
c. Nested if else statement
d. else-if ladder
e. case control structure
f. conditional operator
DJM20032 C PROGRAMMING
3.0 Apparatus
a) Computer
3.1.1 Software Code- Block
4.0 Procedures
4.1 Understand the task below and answer all the question:
Task 1
Create a program that can add HPNM value if the HPNM> = 3.7, the output will display "Excellent,
keep it up" and if otherwise the output will display "you have to try again"
Task 2
Write a C program to input marks of five subjects mathematic, Bahasa Melayu, English language,
Thermodynamic and Science Computer, calculate percentage and grade according to given
conditions:
If percentage >= 90% : Grade A
If percentage >= 80% : Grade B
If percentage >= 70% : Grade C
If percentage >= 60% : Grade D
If percentage >= 40% : Grade E
If percentage < 40% : Grade F
DJM20032 C PROGRAMMING
Task 3
Write a C program to create menu driven calculator that performs basic arithmetic operations (add,
subtract, multiply and divide) using switch case and functions. The calculator should input two
numbers and an operator from user. It should perform operation according to the operator entered
and must take input in given format.
Task 4
5.0 Results/Data
State the Source code and paste the output for Task 1, Task 2, Task 3 and Task 4 on the section of
result and data.
C Code Output
Task 1
Task 2
Task 3
DJM20032 C PROGRAMMING
Task 4
6.0 Discussion
A) “if… else… if” and “switch …case” both programming constructs has ability to take decision based
on conditions. Both are almost similar in nature. However, there is always a debate among
beginners which to use and when to use what?? Explain your understanding when is suitable to
use “if… else… if” and “switch …case”?
1.0 TITLE:
o A brief, concise, yet description title
o An example of a title would be: "Effects of Ultraviolet Light on Borax Crystal Growth Rate".
3.0 THEORY
o Any theory related to experiment must be explained clearly with diagram, figures and so on.
o Include graph, formulas and figures (if any) related to experiment theory.
4.0 APPARATUS/EQUIPMENTS
o Brief explanation of equipment.
o Draw and label the equipment.
6.0 PROCEDURES
o Write in passive sentences about all the steps taken during the experiment.
o Draw and label any related figures if necessary.
7.0 RESULT/DATA
o Data tabulation with units
o Data processing (plotting graph, calculation to obtain the results of the experiments.
8.0 DISCUSSION
o Discuss or answers given questions.
o Discuss comparison between theory and data collection
10.0 REFERENCES
o State all the references that used