0% found this document useful (0 votes)
9 views

JCS2121 C Lab Manual Final Updated

Uploaded by

Ife Amaya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

JCS2121 C Lab Manual Final Updated

Uploaded by

Ife Amaya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

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, Narayanapuram, Pallikaranai,Chennai-600100

PROGRAMMING IN C
JCS2121

RECORD NOTEBOOK
ACADEMIC YEAR: 2024-25
I YEAR / I SEMESTER
REGULATION 2023

DEPARTMENT OF SCIENCE AND HUMANITIES


(COMMON TO ALL B.E./B.TECH BRANCHES)
VISION OF THE INSTITUTION

Jerusalem College of Engineering is committed in emerging as an international institution of excellence


in imparting the finest quality engineering, technology and management education rooted in ethical and
societal values through various academic programs, multi-disciplinary research, consultancy and
entrepreneurship activities, and hence in contributing towards social transformation and nation building

MISSION OF THE INSTITUTION

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

PROGRAM OUTCOMES (POs)

PO1 : Engineering knowledge : Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering problems.

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.

PO10 : Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend and write effective
reports and design documentation ,make effective presentations, and give and receive clear instructions.

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

.............................................................................Laboratory during the year 2024–25.

Signature of Lab In-charge Signature of Head of the Department

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:

1. Usage of Basic Linux commands


2. C Programming using Simple I/O Statements, operators and expressions.
3. C Programming using decision making and looping.
4. Simple programming for one dimensional and two-dimensional arrays.
5. Solving problems using Strings.
6. C Programming using user defined functions (Pass by value and Pass by reference).
7. C Programming using Recursion.
8. C Programming using Pointers and Array of Pointers.
9. C Programming using structures and union.
10. C Programming using storage classes.
11. C Programming using Files.

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.

Linux Directory Commands


1. pwd Command
The pwd command is used to display the location of the current working directory.
Syntax: pwd
Output:

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:

10. rename Command


The rename command is used to rename files. It is useful for renaming a large group of files.
Syntax: rename 's/old-name/new-name/' files
Output:

11. head Command


The head command is used to display the content of a file. It displays the first 10 lines of a file.
Syntax: head <file name>
Output:

12. tail Command


The tail command is similar to the head command. The difference between both commands is that
it displays the last ten lines of the file content. It is useful for reading the error message.
Syntax: tail <file name>
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

14. sudo command


Sudo command will allow you to run the command in elevated rights and once the command is
executed you will be back to your normal rights and permissions.
Example – shutdown command the shutdown command safely turns off the computer system.
sudo shutdown 2 – shutdown and turns of the computer after 2 minutes
sudo apt-get install package name

15. pwd – Print Working Directory


One way to identify the directory you are working in is the pwd command
It displays the current working directory path and is useful when directory changes are often
Syntax: pwd
Output:

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

19. Calendar command:


Syntax: $cal
Output:

3
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

20. Date command


$date

$date +%A

$date +%a

$date +%b

$date +%B

$date +%D

$date +%H

$date +%M

$date +%S

$date +%Y

$date +%y

21. who command


Syntax: $who
Output:

22. who am I command


Syntax: $whoami
Output:

RESULT

Program(3) Execution(3) Result(2) Viva(2) Total (10)

4
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

C PROGRAMMING USING SIMPLE I/O STATEMENTS,


Ex. No. :2.a
OPERATORS AND EXPRESSIONS
Date: AREA AND VOLUME OF SPHERE

AIM:
Write a C program to find the area and volume of sphere.

ALGORITHM:

Step 1: Start the program.


Step 2: Input Radius of sphere as R.
Step 3: Calculate Area = 4*3.14*R*R
Step 4: Calculate Volume = (4/3)*3.14*R*R*R
Step 5: Display the values of Area and Volume.
Step 6: Stop the program.

PROGRAM:

9
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

10
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

C PROGRAMMING USING SIMPLE I/O STATEMENTS ,


Ex. No. :2.b
OPERATORS AND EXPRESSIONS
Date: SIMPLE INTEREST AND COMPOUND INTEREST

AIM:
To Write a C Program to calculate Simple Interest and Compound Interest.

ALGORITHM:

Step 1: Start the program


Step 2: Read the values of principal amount (P), Number of years (N) and
rate of interest (R) as inputs
Step 3: Calculate simple interest using the formula SI = P*N*R / 100.
Step 4: CI=P * pow(1+R/100, N)-P;
Step 5: Display the value of simple interest (SI) and compound interest (CI)
Step 6: Stop the program

PROGRAM:

11
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

12
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

C PROGRAMMING USING SIMPLE I/O STATEMENTS ,


Ex. No. :2.c
OPERATORS AND EXPRESSIONS
Date: ARITHMETIC OPERATIONS

AIM:
To write a C program to perform the arithmetic operations addition, subtraction, multiplication,
division and modulus operation.

ALGORITHM:

Step 1: Start the program.


Step 2: Read the values of a and b as inputs.
Step 3: Apply the operators +, -, *, / and % to perform addition, subtraction,
multiplication, division and modulus operations.
Step 4: Display the values of sum, difference, product, quotient and remainder.
Step 5: Stop the program.

PROGRAM:

13
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT

Program(3) Execution(3) Result(2) Viva(2) Total (10)

14
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

Ex. No.: 3.a C PROGRAMMING USING DECISION MAKING AND LOOPING

Date: PASS OR FAIL USING IF

AIM:
To write a C program to check whether the given mark is pass or fail.

ALGORITHM:

Step 1: Start the program.


Step 2: Read mark M as input.
Step 3: If the mar k is greater than 35 , print “Pass”; ot herwise print “Fail”
Step 4: Stop the program.

PROGRAM:

15
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

16
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

Ex. No. : 3.b C PROGRAMMING USING DECISION MAKING AND LOOPING

Date: PRINTING GRADES USING IF ELSE

AIM:
To write a C program to print the grade of a student.

ALGORITHM:

Step 1: Start the program.


Step 2: Read the mark M of a student as input.
Step 3: If M >= 90 print “Grade O”,
otherwise check if M>=80 print “Grade A+”,
otherwise check if M>=70 print “Grade A”,
otherwise check if M>=60 print “Grade B”,
otherwise check if M>=50 print “Grade C”,
otherwise check if M>=40 print “Grade D”,
otherwise check if M>=35 print “Grade E”,
otherwise check if M<35 print “Fail”.
Step 4: Stop the program.

PROGRAM:

17
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

11
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

Ex. No. : 3.c C PROGRAMMING USING DECISION MAKING AND LOOPING

Date: DAYS OF A WEEK USING SWITCH CASE

AIM:
To write a C program to print the Days of a week using Switch case.

ALGORITHM:

Step 1: Start the program.


Step 2: Enter a value between 1 to 7
Step 3: Switch the value which matches with the cases
Step 4: If case 1 , Print “Monday”
Step 5: If case 2 , Print “Tuesday”
Step 6: If case 3 , Print “Wednesday”
Step 7: If case 4, Print “Thursday”
Step 8: If case 5, Print “Friday”
Step 9: If case 6, Print “Saturday”
Step 10: If case 7, Print “Sunday”
Step 11: Stop the program.

PROGRAM:

12
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

13
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

Ex. No. : 3.d C PROGRAMMING USING DECISION MAKING AND LOOPING

Date: PYRAMID USING NESTED FOR LOOP

AIM:
To write a C program to print a pyramid that illustrates nested for-loop.

ALGORITHM:

Step 1: Start the program.


Step 2: Initialize two variables i and j.
Step 3: For each iteration of i, set the inner loop j to execute
Step 4: Place the inner loop statement to Print “*”
Step 5: Stop the program.

PROGRAM:

14
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

15
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

Ex. No. : 3.e C PROGRAMMING USING DECISION MAKING AND LOOPING

Date: FIBONACCI SERIES

AIM:
To write a C program to print the Fibonacci series.

ALGORITHM:

Step 1: Start the program.


Step 2: Read a number n upto which the Fibonacci series need to be printed.
Step 3: Initialize the first and second number.
Step 4: Print the first and second number.
Step 5: Initialize the for loop upto n . Add the first and second number.
Step 6: Print the sum
Step 7: Stop the program

PROGRAM:

16
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

17
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

Ex. No. : 3.f C PROGRAMMING USING DECISION MAKING AND LOOPING

Date: DISPLAY THE DIGITS OF A NUMBER

AIM:
To write a C program to find and display the digits of a number.

ALGORITHM:

Step 1: Start the program.


Step 2: Read a number num as input.
Step 3: Initialize sum = 0.
Step 4: If num <= 0, go to Step 9.
Step 5: Compute rem = num % 10.
Step 6: Display rem.
Step 7: Compute num = num / 10.
Step 8: Repeat steps 5 to 7 until num = 0.
Step 9: Stop the program.

PROGRAM:

18
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

19
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

Ex. No. : 3.g C PROGRAMMING USING DECISION MAKING AND LOOPING

Date: PALINDROME NUMBER

AIM:
To write a C program to check whether the given number is Palindrome or not.

ALGORITHM:

Step 1: Start the program.


Step 2: Read a number num as input.
Step 3: Initialize sum = 0 and num1 = num.
Step 4: Compute rem = num % 10.
Step 5: Compute sum = (sum *10)+ rem
Step 6: Compute num = num / 10.
Step 7: Repeat steps 4 to 6 until num > 0.
Step 8: If sum = num1, display “the number is Palindrome number” else display “the
number is not a Palindrome number”.
Step 9: Stop the program.

PROGRAM:

20
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

21
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

SIMPLE PROGRAMMING FOR ONE DIMENSIONAL AND TWO


Ex. No. : 4.a
DIMENSIONAL ARRAYS
Date: SMALLEST ELEMENT IN AN ARRAY

AIM:
To write a C program to find the smallest element in an array.

ALGORITHM:

Step 1: Declare and initialize an array.


Step 2: Store first element in the variable min.
Step 3: For i=0 to n, compare the first element with min element

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

Step 6: Print the smallest element

PROGRAM:

22
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

23
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

SIMPLE PROGRAMMING FOR ONE DIMENSIONAL AND TWO


Ex. No. : 4.b
DIMENSIONAL ARRAYS
Date: SORTING ARRAY ELEMENTS

AIM:
To write a C program to sort the elements of an array in ascending order.

ALGORITHM:

Step 1 : Start the program.


Step 2: Declare an array of size n.
Step 3: Read n elements as input and store them in the array A.
Step 4: Repeat Step 5 for n number of times using iteration variable i.
Step 5: Repeat Step 6 for n number of times using iteration variable j.
Step 6: If A[j] > A[j+1], swap A[j] and A[j+1] using temporary variable.
Step 7: Display the sorted array.
Step 8: Stop the program

PROGRAM:

24
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

25
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

SIMPLE PROGRAMMING FOR ONE DIMENSIONAL AND TWO


Ex. No. : 4.c
DIMENSIONAL ARRAYS
Date: MATRIX ADDITION AND SUBTRACTION

AIM:
To write a C program to find the sum and difference between 2 matrices.

ALGORITHM:

Step 1: Start the program.


Step 2: Read the inputs, the number of rows and number of columns as m and n.
Step 3: Read 2 matrices A and B as input with m rows an n columns using nested loops.
Step 4: Repeat Step 5 for m times using i as iteration variable.
Step 5: Repeat Step 6 for n times using j as iteration variable
Step 6: Compute sum[i][j] = A[i][j] + B[i][j] and diff[i][j] = A[i][j] - B[i][j].
Step 7: Display the matrices sum and diff using nester for loops.
Step 8: Stop the program.

PROGRAM:

26
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

27
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

SIMPLE PROGRAMMING FOR ONE DIMENSIONAL AND TWO


Ex. No. : 4.d
DIMENSIONAL ARRAYS
Date: MATRIX MULTIPLICATION

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:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

29
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

Ex. No. : 5 SOLVING PROBLEMS USING STRINGS

Date: STRING MANIPULATION FUNCTIONS

AIM:
To write a C program to use string manipulation functions.

ALGORITHM:

Step 1: Start the program.


Step 2: Include the header file string.h
Step 3: Read 2 strings A and B as inputs.
Step 4: Find and display the length of A and B using strlen( ) function.
Step 5: Concatenate A and B as a new string C using strcat( ) function and display C.
Step 6: Compare the strings A and B using strcmp( ) function and display whether they
are the same or different strings.
Step 7: Convert the characters in A into lower case letters using strlwr( ) function and
display A.
Step 8: Convert the characters in A into upper case letters using strupr( ) function and
display A.
Step 9: Reverse the string A using strrev( ) function and display the reversed string.
Step 10: Copythe string A to B using strcpy( ) function and display A and B.
Step 11: Stop the program.

PROGRAM:

30
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

31
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

C PROGRAMMING USING USER DEFINED FUNCTIONS (PASS BY


Ex. No. : 6.a
VALUE AND PASS BY REFERENCE)
Date: SUM OF TWO NUMBERS – USING PASS BY VALUE

AIM:
To write a C program to find sum of two numbers using pass by value method.

ALGORITHM: Sum using pass by value


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( ) bypassing a and b as arguments.
Step 5: Display the sum of values of a and b.
Step 6: Stop the program.

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:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

33
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

C PROGRAMMING USING USER DEFINED FUNCTIONS (PASS


Ex. No. : 6.b
BY VALUE AND PASS BY REFERENCE)
Date: SUM OF TWO NUMBERS – USING PASS BY REFERENCE

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.

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:

34
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

35
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

Ex. No. : 7 C PROGRAMMING USING RECURSION


Date: FACTORIAL OF A NUMBER USING RECURSION

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:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

37
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

Ex. No. : 8 C PROGRAMMING USING POINTERS AND ARRAY OF POINTERS

Date: MAXIMUM ELEMENT IN AN ARRAY

AIM:
To write a C program to find the maximum element in an array using pointers.

ALGORITHM:

Step 1: Start the program.


Step 2: Declare an array to store n elements.
Step 3: Declare an array of pointers.
Step 4: Initialize each pointer to point to the corresponding element in the original array.
Step 5: Initialize the variable max with the element pointed to bythe first pointer.
Step 6: If the element pointed to by the next pointer is > max, update max with that
element.
Step 7: Iterate through the arrayof pointers by repeating Step 6 n-1 times.
Step 8: Display max.
Step 9: Stop the program.

PROGRAM:

38
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

39
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

Ex. No. : 9.a C PROGRAMMING USING STRUCTURES AND UNION

Date: STUDENTS GRADE USING STRUCTURE

AIM:
To write a C program to find the grade scored by a student using structures.

ALGORITHM:

Step 1: Start the program.


Step 2: Define the structure student with student id, name, 5 subject test marks, average
marks and grade.
Step 3: Declare a structure variable.
Step 4: Read student id, name and 5 subject marks.
Step 5: Calculate the average mark.
Step 6: Compute the grade based on the average marks.
Step 7: Display the subject marks, average mark and grade.
Step 8: Stop the program.

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:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

42
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

Ex. No. : 9.b C PROGRAMMING USING STRUCTURES AND UNION

Date: BANK CUSTOMER DETAILS – USING UNION

AIM:
To write a C program to store personal details of a bank customer using union.

ALGORITHM:

Step 1: Start the program.


Step 2: Define a union person with account number, name, city and balance amount.
Step 3: Declare a union variable.
Step 4: Read the values of account number, name, city and balance amount.
Step 5: Display the values of account number, name, city and balance amount
Step 6: Display the size of the union variable.
Step 7: Stop the program.

PROGRAM:

43
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

RESULT:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

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:

Step 1: Start the program.


Step 2: Define 4 functions auto1, extern1, register1 and static1 with different storage
classes.
Step 3: In auto1 function, initialize and display the value of an auto variable.
Step 4: In register1 function, initialize and display the value of a register variable.
Step 5: In extern1 function, declare an extern variable and display the cube value of the
extern variable.
Step 6: In static1 function, declare and initialize a static variable.
Step 7: Increment its value inside the function.
Step 8: Display the value of the static variable, every time the function is called.
Step 9: Stop the program.

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:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

48
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

Ex. No. : 11 C PROGRAMMING USING FILES


Date: READING, WRITING AND APPEND OPERATIONS IN FILE

AIM:
To write a C program to implement file operations.

ALGORITHM:

Step 1: Start the program.


Step 2: Declare 2 files f1 and f2 using file pointer.
Step 3: Open the file f1 in write mode.
Step 4: Write the text content into the file f1.
Step 5: Close the file.
Step 6: Open the file f1 in read mode and f2 in write mode.
Step 7: Read the contents from f1 and write it character by character in file f2 till the end
of file is reached in f1.
Step 8: Close the files f1 and f2.
Step 9: Open the file f1 in read mode and f2 in append mode.
Step 10: Read the contents from f1 and append it character by character to file f2 till the
end of file is reached in f1.
Step 11: Close the files f1 and f2.
Step 12: Stop the program.

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:

Program(3) Execution(3) Result(2) Viva(2) Total (10)

51
JCS2121: PROGRAMMING IN C LABORATORY DEPT. OF SCIENCE & HUMANITIES 2024-25

VIVA QUESTIONS

1. What is the purpose of the main() function in a C program?

Answer: The main() function is the entrypoint of a C program. It is where the execution of the
program begins.

2. Explain the difference between ++i and i++ operators in C.

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.

3. What is the role of #include<stdio.h> in a C program?

Answer: #include<stdio.h> is a preprocessor directive that includes the standard input-output


library in the C program, allowing the use of functions like printf() and scanf().

4. Describe the difference between scanf() and printf() functions in C.

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

5. How do you declare a constant in C? Give an example.

Answer: Constants in C can be declared using the const keyword. For example: const int
MAX_VALUE = 100;

6. Explain the difference between == and = operators in C.

Answer: == is the equality operator used for comparison, while = is the assignment operator used
to assign a value to a variable.

7. What is the significance of sizeof() operator in C? Provide an example.

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

8. Describe the purpose of the typedef keyword in C.

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;

10. Explain the difference between while and do-while loops in C.

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

You might also like