0% found this document useful (0 votes)
3 views11 pages

C PROGRAM MANUAL COM 121

The document is a practical manual for C programming language exercises, detailing installation of the DEV C/C++ software and various programming concepts. It includes lab exercises on standard input/output operations, control structures, functions, arrays, pointers, and data types like structures and unions. Each exercise outlines objectives, procedures, and exercises for students to complete, with conclusions summarizing the skills learned.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

C PROGRAM MANUAL COM 121

The document is a practical manual for C programming language exercises, detailing installation of the DEV C/C++ software and various programming concepts. It includes lab exercises on standard input/output operations, control structures, functions, arrays, pointers, and data types like structures and unions. Each exercise outlines objectives, procedures, and exercises for students to complete, with conclusions summarizing the skills learned.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

PRACTICAL MANUAL

ON
C PROGRAMMING LANGUAGE
(COM 121)
LAB EXERCISE 1

TITLE: INSTALLING DEV C/C++ SOFTWARE

OBJECTIVES:

1. Know how to install the DEV C/C++ Compiler

2. Understand the benefits of use of DEV C/C++ for windows as an application tool.

EQUIPMENT(S): Computer systems, DEV C/C++ compiler

PROCEDURE:

1. Download Dev-C++ Installer:


 Visit the Dev-C++ Download Page on SourceForge.
 Download the latest version of the Dev-C++ installer (usually with a filename
like Dev-Cpp X.XX TDM-GCC 4.9.2 Setup.exe).
2. Run the Installer:
 Run the downloaded installer.
 If prompted, allow the installer to make changes to your device.
3. Installation Wizard:
 Follow the installation wizard steps:
 Choose the language for the installation.
 Accept the license agreement.
 Choose the destination folder for Dev-C++ installation.
4. Select Components:
 Choose the components you want to install:
 The default components are usually sufficient for C/C++ development.
5. Choose Start Menu Folder:
 Select the Start Menu folder for program shortcuts.
6. Install Additional Components (Optional):
 Optionally, you can install additional components like MSYS (providing Unix
tools) during the installation process.
7. Complete the Installation:
 Click "Install" to start the installation process.
8. Finish Installation:
 Once the installation is complete, click "Finish" to exit the installer.

EXERCISE:

a. Highlight the with a clear screenshots, the step taken to install DEV C/C++
compiler on your PCs
b. Document your reports and print out
CONCLUSION: The students have been taught the overview of the DEV C/C++ Integrated
Development Environment and the various components on the IDE.

NOTE: The technologist/Lab Assistant should assist the students during the practical work.
LAB EXERCISE 2

TITLE: UNDERSTAND STANDARD INPUTS AND OUTPUT OPERATIONS

OBJECTIVE: At the end of the practical class, student should be able to demonstrate the use of Input
(scanf) for getting user’s input and Output operation (printf) to display the result of
processes.

EQUIPMENT(S): Computer systems, DEV C/C++ compiler

PROCEDURE:

1. Load the C compiler from the system


2. Start the processes to create
3. Use the scanf to input data into the system via keyboard
4. Use the printf to display the result of processed data
5. Generate your result and shutdown

EXERCISE:

a. Write a C program that accept 5 numbers from user and display the sum and
average of the numbers
b. Develop a C program that takes a number as input and prints the multiplication
table for that number up to 10.

CONCLUSION: The students have been shown and taught how to work with functions,
modules and libraries C programming Language
NOTE: The technologist/Lab Assistant should assist the students during the practical work.
LAB EXERCISE 3

TITLE: UNDERSTAND CONTROL STRUCTURE (DECISION MAKING AND LOOPS)

OBJECTIVE: At the end of the lab exercise, student should be able to demonstrate how to use
different control structures in program

EQUIPMENT(S): Computer systems, DEV C++ compiler

PROCEDURE

1. Begin by grasping the fundamental control structures in C:


2. Sequence Structure: Code is executed in a linear manner.
3. Selection Structure (if-else): Execute different blocks of code based on a
condition.
4. Iteration Structure (loops): Repeat a block of code as long as a condition is
true (for, while, do-while).
5. Focus on understanding how these structures control the flow of a program.

EXERCISE:

a. Develop menu driven C program for a simple calculator that can perform
addition, subtraction, multiplication, and division based on user input. Use a
switch statement.
b. Create a C program to display the multiplication table of 12 x 12 using a for
loop.

CONCLUSION: The students have been shown and taught how to work with control structures
and its implementation in decision making using C programming Language
NOTE: The technologist/Lab Assistant should assist the students during the practical work.
LAB EXERCISE 4

TITLE: UNDERSTAND THE FUNCTIONS AND SCOPE RULES

OBJECTIVE: At the end of the Lab exercise, the students should be able to understand what functions
and scope rules are and also demonstrate how to perform function calls in program

EQUIPMENT(S): Computer systems, DEV C/C++ compiler

PROCEDURE

1. Function Declaration:
 Declare the function prototype. Specify the return type, function name,
and parameters (if any).
int add(int a, int b);
2. Function Definition:
 Implement the function. Define the code that performs the desired
task.
int add(int a, int b) { return a + b; }
3. Main Program:
 In the main function or any other function, call the defined function.
int main() { int result = add(5, 3); // Use the result or print it return 0; }
4. Compile and Run:
 Compile the C code using a C compiler (e.g., DEV C/C++).
 Execute the compiled program to see the result.
5. Check the Output:
 Verify that the program produces the expected output based on the
defined function.

EXERCISE:

a. Write a C program that defines a function add which takes two integers as
parameters and returns their sum. In the main function, call this function and
print the result.
b. Write a C program that includes a function power to calculate the power of a
number. The function should take two integers as parameters (base and
exponent) and return the result. In the main function, call this function and
print the result.

CONCLUSION: The students have been shown and taught how to work with functions, and
scope rules C programming Language.
NOTE: The technologist/Lab Assistant should assist the students during the practical work.
LAB EXERCISE 5

TITLE: UNDERSTAND ARRAYS AND STRINGS

OBJECTIVE: At the end of the Lab exercise, the students should be able to understand what arrays and
strings are and also demonstrate how to implement an array in programs.

EQUIPMENT(S): Computer systems, DEV C++ compiler

PROCEDURE

1. Array Declaration:
 Declare an array by specifying the data type and size.
int numbers[5];
2. Array Initialization:
 Optionally, initialize the array elements.
int numbers[5] = {1, 2, 3, 4, 5};
3. Array Indexing:
 Access individual elements using indices (starting from 0).
int thirdElement = numbers[2];
4. Array Modification:
 Modify elements by assigning new values.
numbers[2] = 10;
5. Array Iteration:
 Use loops to iterate through the array.
for (int i = 0; i < 5; i++) { // Access and use numbers[i] }
6. Multidimensional Arrays (Optional):
 For multidimensional arrays, declare and access elements with
multiple indices.
int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
7. Array as Function Parameter:
 Pass arrays to functions by reference.
void printArray(int arr[], int size) { // Function code }
8. Pointer Arithmetic (Optional):
 Explore pointer arithmetic for advanced array manipulation.
int *ptr = numbers; int thirdElement = *(ptr + 2);
9. Dynamic Memory Allocation (Optional):
 For dynamic arrays, use functions like malloc and free.
int *dynamicArray = (int *)malloc(5 * sizeof(int));
10. Compile and Run:
 Compile the C code using a C compiler (e.g., DEV C/C++).
 Execute the compiled program to see the result.
EXERCISE:

a. Write a C program that calculates and prints the sum of all elements in an integer
array.
b. Develop a C program that copies elements from one integer array to another. Print
both the original and copied arrays.

CONCLUSION: The students have been shown and taught how to work with arrays, and strings
C programming Language.
NOTE: The technologist/Lab Assistant should assist the students during the practical work.
LAB EXERCISE 6

TITLE: UNDERSTAND POINTER OPERATIONS

OBJECTIVE: At the end of the Lab exercise, the students should be able to understand what pointer
operation and also demonstrate how to how to use pointers in programs.

EQUIPMENT(S): Computer systems, DEV C/C++ compiler

PROCEDURE:

1. Pointer Declaration:
 Declare a pointer variable of a specific data type.
int *ptr;
2. Assign Address to Pointer:
 Assign the address of a variable to the pointer.
int number = 10; int *ptr = &number;
3. Dereference Pointer:
 Access the value at the memory location pointed to by the pointer
using the dereference operator *.
int value = *ptr;
4. Pointer Arithmetic:
 Explore pointer arithmetic for navigating through arrays or allocating
memory.
int arr[5] = {1, 2, 3, 4, 5}; int *ptr = arr; // Points to the first element
int thirdElement = *(ptr + 2);
5. Null Pointer:
 Use null pointers to represent no valid address.
int *ptr = NULL;
6. Function Pointers (Optional):
 Declare and use function pointers for advanced applications.
int add(int a, int b) { return a + b; } int (*ptr)(int, int) = &add;
7. Dynamic Memory Allocation:
 Use pointers with malloc, calloc, and free for dynamic memory
allocation.
int *dynamicArray = (int *)malloc(5 * sizeof(int));
8. Pointer to Structures (Optional):
 Explore pointers to structures for working with complex data types.
struct Point { int x; int y; }; struct Point p1; struct Point *ptr = &p1;
9. Pointer as Function Parameter:
 Pass pointers to functions for efficient parameter passing.
void updateValue(int *ptr) { *ptr = 20; }
10. Compile and Run:
 Compile the C code using a C compiler (e.g., GCC).
 Execute the compiled program to see the result.
11. Check the Output:
 Verify that the program produces the expected output based on pointer
operations.

EXERCISE:

a. Write a C program that uses a pointer to find and print the maximum element
in an array of integers.
b. Develop a C program that uses function pointers to implement a basic
calculator. Define functions for addition, subtraction, multiplication, and
division, and use function pointers to perform operations based on user input.

CONCLUSION: The students have been shown and taught how to work with pointers operation
in C programming Language.
NOTE: The technologist/Lab Assistant should assist the students during the practical work.
LAB EXERCISE 7

TITLE: UNDERSTAND STRUCTURES AND UNION DATA TYPES

OBJECTIVE: At the end of the Lab exercise, the students should be able to understand what structures
and union data types are and also demonstrate how to implement structures and union
types in programs.

EQUIPMENT(S): Computer systems, DEV C++ compiler

PROCEDURE

1. Define Structure:
 Define a structure by specifying the data types of its members.
struct Point { int x; int y; };
2. Declare Structure Variable:
 Declare variables of the structure type.
struct Point p1;
3. Access Structure Members:
 Access members of the structure using the dot operator.
p1.x = 10; p1.y = 20;
4. Initialize Structure:
 Optionally, initialize the structure at the time of declaration.
struct Point p2 = {5, 15};
5. Pass Structure to Function:
 Pass structures to functions by value or reference.
void printPoint(struct Point p) { // Access members using p.x and p.y }

EXERCISE:

a. Write a C program that defines a structure Point representing coordinates (x,


y). Initialize two points, calculate and print the distance between them.
b. Develop a C program that uses a union Storage to store integer, float, and
character data. Write functions to input and print each type of data.

CONCLUSION: The students have been shown and taught how to work with structures and
union types in C programming Language.
NOTE: The technologist/Lab Assistant should assist the students during the practical work.

You might also like