Professional Documents
Culture Documents
Lab1 - DJM20032 Naim
Lab1 - DJM20032 Naim
C PROGRAMMING
DJM 20032
LABAROTARY 1
DJM20032 C PROGRAMMING
LABORATORY 1
Objective(s)
PROBLEM 1 (CLO2:P3)
Develop and design program to calculate and display the volume of CUBE having its height
(h = 10cm), width (w=12cm) and depth (d = 8cm).
Problem Analysis
The problem is to calculate the volume of a CUBE having its inputs parameters identified as:
Height (integer type), width (integer type) and depth (integer type). The output of the
program is to display the volume; hence the output parameter is identified as vol (integer
type). During the processing or calculation phase, we don’t need any extra parameters
(variables) for this problem.
The volume of the cube is the multiplication of its height, width and depth, hence the
mathematical formula to calculate volume is:
Pseudo Code
w(int)
d(int)
Algorithm:
1. Start
2. Define variables: h(int), w(int), d(int), vol(int)
3. Assign value to variables: h = 10, w=12, d=8.
4. Calculate the volume as: vol = h*w*d.
5. Display the volume (vol)
6. Stop Flowchart:
Flowchart
[10 marks]
Program:
[10 marks]
Output
[5 marks]
PROBLEM 2 (CLO2:P3)
Develop a complete program that calculates the product of three integers. The program
should do each of the following:
Problem Analysis
i. State that the program will calculate the product of three integers.
ii. Define the variables x, y, z, and result to be of type int.
iii. Prompt the user to enter three integers.
iv. Read three integers from the keyboard and store them in the variables x, y, and z.
v. Compute the product of the three integers contained in variables x, y, and z, and
assign the result to the variable result.
vi. Print "The product is" followed by the value of the integer variable result.
[5 marks]
Algorithm:
1. Start
Emgr. Mohd Nazri bin Saad
DJM20032 C PROGRAMMIN Page |
[10 marks]
Pseudo Code
[10 marks]
Flowchart
Emgr. Mohd Nazri bin Saad
DJM20032 C PROGRAMMIN Page |
[10 marks]
Program
[10 marks]
Output
Enter value of x : 5
Enter value of y : 5
Enter value of z : 5
[5 marks]
Keyword:
1. Keywords are reserved words in a programming language that have predefined meanings and are
used to perform specific tasks or operations.
2. They cannot be used as identifiers (variable names, function names, etc.) because they are
already predefined by the language.
3. Keywords are reserved words in a programming language that have predefined meanings and
cannot be used as identifiers (variable names, function names, etc.).
4. Examples of keywords in Python include if, else, for, while, def, class, import, True, False, and
None.
Identifier:
5. Identifiers are user-defined names given to various programming elements such as variables,
functions, classes, etc.
6. They are used to uniquely identify these elements within a program.Identifiers can consist of
letters, digits, and underscores (_), but must start with a
7. letter or an underscore.
8. Identifiers are case-sensitive, meaning my_variable, My_Variable, and
9. MY_VARIABLE are considered different identifiers.
[10 marks]
[6 marks]
.
A. Visual Representation: Flowcharts provide a visual representation of the
logical flow of a program. They allow programmers to visualize the structure of
the program, including decision points, loops, and the sequence of operations.
[4 marks]
10. Conclusion
In conclusion, keywords and identifiers play crucial roles in programming languages like C.
Keywords are reserved words with predefined meanings, used for specific purposes such as
defining control structures or data types. Identifiers, on the other hand, are user-defined
names given to variables, functions, and other entities, following certain rules like starting
with a letter or underscore and being case-sensitive.
[5 marks]