JCS2121 C Lab Manual Final Updated
JCS2121 C Lab Manual Final Updated
PROGRAMMING IN C
JCS2121
RECORD NOTEBOOK
ACADEMIC YEAR: 2024-25
I YEAR / I SEMESTER
REGULATION 2023
Generating abundant resources and making conducive policies, the management led by the
Chairperson strives towards promoting globally competitive academic programs augmented with
value added courses, in-plant training, co-curricular activities and ambience that support
intellectual growth and skill acquisition.
Promoting collaborative trans-border research programs, continuing education in synergy with
academia, industries and research organizations leading to real time solutions and life-long
learning.
Transforming young men and women into competent professionals and entrepreneurs motivated
by a passion for professional excellence, driven by human values and proactively engage in the
betterment of the society through innovative practices and academic excellence.
Facilitating effective interaction among faculty members and students and fostering network of
alumni, industries, institutions and other stake holders for successful career gain and placement.
PO2 : Problem analysis : Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics, natural
sciences, and engineering sciences.
PO3 : Design / development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate consideration for
the public health and safety, and the cultural, societal, and environmental considerations.
PO4: Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
PO7: Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the engineering practice.
PO9: Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multi disciplinary settings.
PO11 : Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and leader in
a team,to manage projects and in multi disciplinary environments.
PO12: Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
JERUSALEM COLLEGE OF ENGINEERING
(An Autonomous Institution)
(Approved by AICTE, Affiliated to Anna University Accredited by NBA and NAAC with ‘A’ Grade)
Velachery Main Road, Pallikaranai, Chennai – 600100
Name……………………………………………………………………………………
Year…………………………………Semester………………Branch………………
Regulation……………………..
Register No.
Certified that this is a Bonafide Record work done by the above student in the …………..
EXAMINER
DATE:
INTERNAL EXAMINER
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
SYLLABUS
PROGRAMMING IN C L T P C
JCS2121
PROGRAMMING IN C LABORATORY 3 0 2 4
COURSE OBJECTIVES
To understand the concepts of C Language.
To implement programs using basic constructs of C
To develop C programs using Arrays and Strings
To develop modular applications in C using functions and Pointers.
To be able to use File operations and Structures in C
LIST OF PROGRAMS
Implement the following programs:
TOTAL: 30 Periods
COURSE OUTCOMES:
On completion of the course, the students should be able to:
Develop efficient algorithms for solving a problem.
Develop simple applications using various operators in C.
Design and Implement applications using Array and Strings.
Develop applications using Functions and Pointers.
Design and Develop applications using Structures and Files.
TEXT BOOKS
1. Paul J. Deitel, Harvey M. Deitel , “C: How to Program”, 9th Edition, Prentice Hall.
2. Reema Thareja, “Programming in C”, Oxford University Press, Second Edition, 2016.
3. E. Balaguruswamy, “Programming in ANSI C”, 8th Edition, 2019, McGraw Hill
Education.
4. Yashavant P. Kanetkar. “Let Us C”, BPB Publications, 16th edition 2017.
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
REFERENCE BOOKS
1. Pradip Dey, Manas Ghosh, “Programming in C”, 2nd Edition, 2018, Oxford University
Press, ISBN: 978-01-9949-147-6.
2. Kernighan B.W and Dennis M. Ritchie, “The C Programming Language”, 2nd Edition,
2015, Pearson Education India, ISBN: 978-93-3254-944-9.
3. Jacqueline A Jones and Keith Harrow, “Problem Solving with C”, Pearson Education.
ISBN: 978-93-325-3800-9.
4. PradipDey, ManasGhosh, “Programming in C - As per the latest AICTE syllabus”, First
Edition, Oxford University Press, 2018.
5. Byron S Gottfried, “Programming with C”, Schaum’s Outlines, Third Edition, McGraw-
Hill, 2010.
WEBSITE REFERENCES
1. http://elearning.vtu.ac.in/econtent/courses/video/BS/14CPL16.html
2. https://nptel.ac.in/courses/106/105/106105171/
3. https://www.w3resource.com/c-programming-exercises/
4. https://www.programiz.com/c-programming/c-structures-pointers
5. https://www.sitesbay.com/cprogramming/c-applications
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
INDEX
Signature
Ex.No. Date Name of the Experiment Page No. Marks
with Date
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
Signature
Ex.No. Date Name of the Experiment Page No. Marks
with Date
Average Marks:
Signature :
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
Ex. No.:1
USAGE OF BASIC LINUX COMMANDS
Date:
AIM:
To study the usage of basic Linux commands with their examples.
2. mkdir Command
The mkdir command is used to create a new directory under any directory.
Syntax: mkdir <directory name>
Output:
3. rmdir Command
The rmdir command is used to delete a directory.
Syntax: rmdir <directory name>
Output:
4. ls Command
The ls command is used to display a list of content of a directory.
Syntax: ls
Output:
5. cd Command
The cd command is used to change the current directory.
Syntax: cd <directory name>
Output:
6. cat Command
The cat command is a multi-purpose utility in the Linux system. It can be used to create a file,
display content of the file, copy the content of one file to another file, and more.
Syntax: cat > <file name>
Output:
1
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
7. rm Command
The rm command is used to remove a file.
Syntax: rm<file name>
Output:
8. cp Command
The cp command is used to copy a file or directory.
Syntax: cp <existing file name> <new file name>
To copy in the same directory:
Output:
9. mv Command
The mv command is used to move a file or a directory form one location to another location.
Syntax: mv <file name> <directory path>
Output:
13. su Command
The su command provides administrative access to another user. In other words, it allows access
of the Linux shell to another user.
Syntax: su <user name>
Output:
2
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
16. chmod –
This command is used to change mode of a file system object. Files can have r – read, w- write
and x-execute permissions.
Syntax:chmod mode FILE
Example: chmod 744 script.sh
17. echo
This command is used to display a text or a string to the standard output or a file.
Syntax: $ echo “This is an article on basic linux commands”
Output:
18. wc Command
The wc command is used to count the lines, words, and characters in a file.
Syntax: wc <file name>
Output:
18. clear
This command lets you clear the terminal screen.
Syntax: $clear
3
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
$date +%A
$date +%a
$date +%b
$date +%B
$date +%D
$date +%H
$date +%M
$date +%S
$date +%Y
$date +%y
RESULT
4
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
Write a C program to find the area and volume of sphere.
ALGORITHM:
PROGRAM:
9
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
10
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To Write a C Program to calculate Simple Interest and Compound Interest.
ALGORITHM:
PROGRAM:
11
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
12
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to perform the arithmetic operations addition, subtraction, multiplication,
division and modulus operation.
ALGORITHM:
PROGRAM:
13
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT
14
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to check whether the given mark is pass or fail.
ALGORITHM:
PROGRAM:
15
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
16
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to print the grade of a student.
ALGORITHM:
PROGRAM:
17
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
11
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to print the Days of a week using Switch case.
ALGORITHM:
PROGRAM:
12
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
13
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to print a pyramid that illustrates nested for-loop.
ALGORITHM:
PROGRAM:
14
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
15
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to print the Fibonacci series.
ALGORITHM:
PROGRAM:
16
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
17
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to find and display the digits of a number.
ALGORITHM:
PROGRAM:
18
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
19
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to check whether the given number is Palindrome or not.
ALGORITHM:
PROGRAM:
20
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
21
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to find the smallest element in an array.
ALGORITHM:
Step 4: If any element is less than min, min will hold the value of that element.
Step 5: Repeat the steps upto n times
PROGRAM:
22
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
23
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to sort the elements of an array in ascending order.
ALGORITHM:
PROGRAM:
24
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
25
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to find the sum and difference between 2 matrices.
ALGORITHM:
PROGRAM:
26
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
27
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to multiply 2 matrices.
ALGORITHM:
Step 1 Start the program.
Step 2 Read the number of rows and number of columns of the 2matrices as p, q
and r.
Step 3 Read matrix A with p rows and q columns and matrix B with q rows an r
columns as input using nested loops.
Step 4 Repeat Step 5 for p times using i as iteration variable.
Step 5 Repeat Step 6 and 7 for r times using j as iteration variable
Step 6 Initialize C[i][j] = 0.
Step 7 Repeat Step 8 for q times using k as iteration variable
Step 8 Compute C[i][j] = C[i][j] + A[i][k] * B[k][j].
Step 9 Display the matrix C using nester for loops.
Step 10 Stop the program.
PROGRAM:
28
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
29
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to use string manipulation functions.
ALGORITHM:
PROGRAM:
30
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
31
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to find sum of two numbers using pass by value method.
Function: sum(a, b)
Step a: Start the function.
Step b: Add the value of a and b ..
Step c: Store the result in c variable.
Step d: Display the values of c.
Step e: Stop the function.
PROGRAM:
32
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
33
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to find sum of two numbers using pass by reference method.
ALGORITHM :
Sum of two numbers using pass by reference
Step 1: Start the program.
Step 2: Read 2 numbers a and b as inputs.
Step 3: Display the values of a and b .
Step 4: Call the function sum( ) by passing the addresses of a and b as arguments.
Step 5: Display the sum of a and b after adding their values.
Step 6: Stop the program.
PROGRAM:
34
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
35
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to compute the factorial of a number.
ALGORITHM:
Step 1: Start the program.
Step 2: Read a number n as input.
Step 3: Call the function fact( ) by passing n as argument.
Step 4: Display the value f returned by the function.
Step 5: Stop the program.
Function: fact(n)
Step a: Start the function.
Step b: If n = 0 or 1, return 1.
Step c: Calculate f = n * fact(n-1) by calling the function fact( ) using n-1 as argument.
Step d: Return f.
Step e: Stop the function.
PROGRAM:
36
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
37
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to find the maximum element in an array using pointers.
ALGORITHM:
PROGRAM:
38
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
39
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to find the grade scored by a student using structures.
ALGORITHM:
PROGRAM:
40
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
41
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
42
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to store personal details of a bank customer using union.
ALGORITHM:
PROGRAM:
43
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
44
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
Ex. No. : 10
C PROGRAMMING USING STORAGE CLASSES
Date:
AIM:
To write a C program to demonstrate the use of storage classes.
ALGORITHM:
PROGRAM:
45
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
46
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
47
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
48
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
AIM:
To write a C program to implement file operations.
ALGORITHM:
PROGRAM:
49
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
50
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
RESULT:
51
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
VIVA QUESTIONS
Answer: The main() function is the entrypoint of a C program. It is where the execution of the
program begins.
Answer: Both ++i and i++ increment the value of i, but ++i is a pre-increment operator,
meaning it increments i first and then returns the incremented value. On the other hand, i++ is a
post-increment operator, meaning it returns the value of i first and then increments it.
Answer: printf() is used to print formatted output to the standard output (usually the console),
while scanf() is used to read formatted input from the standard input (usually the keyboard).
Answer: Constants in C can be declared using the const keyword. For example: const int
MAX_VALUE = 100;
Answer: == is the equality operator used for comparison, while = is the assignment operator used
to assign a value to a variable.
Answer: sizeof() operator returns the size of a variable or data type in bytes. Example:
sizeof(int) returns the size of an integer data type in bytes.
52
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25
Answer: typedef is used to create a new data type alias. It allows defining custom names for
existing data types, making the code more readable and easier to maintain.
9. What is the role of the NULL pointer in C? Give an example of its usage.
Answer: NULL pointer is a constant pointer that points to nothing. It is often used to initialize
pointers when they are not supposed to point to a valid memory address.
Example: int *ptr = NULL;
Answer: In a while loop, the condition is checked before the execution of the loop's body,
whereas in a do-while loop, the condition is checked after the execution of the loop's body,
guaranteeing that the loop body is executed at least once.
53