Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

DJM20032 C PROGRAMMIN Page |

SULTAN ABDUL HALIM MU’ADZAM SHAH

C PROGRAMMING
DJM 20032
LABAROTARY 1

Name MUHAMMAD NAIM BIN ADULLAH


Reg. No 03DEM23F1024

CLO ASSESTMENT MARKS


CLO2: P3 PRACTICAL /75 /50
CLO2: P3 REPORT /25

Emgr. Mohd Nazri bin Saad


DJM20032 C PROGRAMMIN Page |

DJM20032 C PROGRAMMING

LABORATORY 1

Objective(s)

i. To be familiar with syntax and structure in C programming


ii. To learn problem solving technique using C

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:

vol = height* width* depth. (vol = h*w*d)

Pseudo Code

Input variables Processing Output variables Necessary header


variables/calculations files/functions/macros
h(int) vol = h*w*d vol (int) stdio.h

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:

Emgr. Mohd Nazri bin Saad


DJM20032 C PROGRAMMIN Page |

Flowchart

[10 marks]

Emgr. Mohd Nazri bin Saad


DJM20032 C PROGRAMMIN Page |

Program:

[10 marks]

Emgr. Mohd Nazri bin Saad


DJM20032 C PROGRAMMIN Page |

Output

Volume of the cube : 960

[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:

i. State that a 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.

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 |

2. Declare variables: x, y, z, result as integers


3. Prompt user to enter the first integer and store it in variable x
4. Prompt user to enter the second integer and store it in variable y
5. Prompt user to enter the third integer and store it in variable z
6. Compute result = x * y * z
7. Display "The product is", result
8. End

[10 marks]

Emgr. Mohd Nazri bin Saad


DJM20032 C PROGRAMMIN Page |

Pseudo Code

Input variables Processing Output variables Necessary header


variables/calculations files/functions/macros
x(int) result = x*y*z result(int)
y(int) Display the
z(int) product is

[10 marks]

Flowchart
Emgr. Mohd Nazri bin Saad
DJM20032 C PROGRAMMIN Page |

[10 marks]

Emgr. Mohd Nazri bin Saad


DJM20032 C PROGRAMMIN Page |

Program

[10 marks]

Emgr. Mohd Nazri bin Saad


DJM20032 C PROGRAMMIN Page |

Output

Enter value of x : 5
Enter value of y : 5
Enter value of z : 5

[5 marks]

REPORT & DISCUSSION (CLO2:P3)

1. Discuss differences between keyword and identifier

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]

Emgr. Mohd Nazri bin Saad


DJM20032 C PROGRAMMIN Page |

2. State THREE (3) keyword in C programming

int: Used to declare integer variables.


char: Used to declare character variables.
void: Used to specify that a function does not return any value or to indicate an empty
parameter list for a function.

[6 marks]

3.Discuss the purposes of flowchart in programming

Flowcharts serve several important purposes in programming:

.
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.

B. Algorithm Design: Before writing actual code, flowcharts can help


programmers design and plan algorithms. They allow programmers to break
down complex problems into smaller, more manageable steps and visualize the
logical flow of these steps.

C. Communication: Flowcharts serve as a means of communication between


programmers, stakeholders, and other team members involved in the software
development process. They provide a common visual language that can be easily
understood by individuals with varying levels of technical expertise.

D. Documentation: Flowcharts can be used as documentation for software


systems. They provide a clear and concise overview of how a program works,
making it easier for developers to understand and maintain the code in the
future.
.

[4 marks]

Emgr. Mohd Nazri bin Saad


DJM20032 C PROGRAMMIN Page |

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]

Emgr. Mohd Nazri bin Saad

You might also like