[go: up one dir, main page]

0% found this document useful (0 votes)
2 views157 pages

Biotech Wb

The document outlines the syllabus and laboratory workbook for the Programming in C course at Prathyusha Engineering College for the academic year 2025-2026. It includes course objectives, a list of experiments, course outcomes, and required textbooks and references. The document also details specific experiments, such as solving quadratic equations and using the ternary operator, along with software/hardware requirements and sample input/output for each experiment.

Uploaded by

Second
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views157 pages

Biotech Wb

The document outlines the syllabus and laboratory workbook for the Programming in C course at Prathyusha Engineering College for the academic year 2025-2026. It includes course objectives, a list of experiments, course outcomes, and required textbooks and references. The document also details specific experiments, such as solving quadratic equations and using the ternary operator, along with software/hardware requirements and sample input/output for each experiment.

Uploaded by

Second
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 157

Prathyusha Engineering College

(Autonomous)

DEPARTMENT OF BIOTECHNOLOGY

B .TECH
Ist YEAR / Ist SEMESTER
ACADEMIC YEAR 2025-2026

241GES111L
PROGRAMMING IN C LABORATORY
[Common to all branches]

WORK BOOK

Prepared by Approved by
Ms.P.SHOBANA DR.W.THAMBA MESHACH
ASST. PROF , DEPT. OF CSE HOD, DEPT. OF CSE
PRATHYUSHA ENGINEERING COLLEGE PRATHYUSHA ENGINEERING COLLEGE
241GES111L PROGRAMMING IN C LABORATORY L T P R C 0 0 4 2
SYLLABUS
COURSE OBJECTIVES:
• To familiarize with C programming constructs.
• To develop programs in C using basic constructs.
• To develop programs in C using arrays.
• To develop applications in C using strings, pointers, functions.
• To develop applications in C using structures.
• To develop applications in C using file processing.

LIST OF EXPERIMENTS:

1. I/O statements, operators, expressions


2. decision-making constructs: if-else, goto, switch-case, break-continue
3. Loops: for, while, do-while
4. Arrays: 1D and 2D, Multi-dimensional arrays, traversal
5. Strings: operations
6. Functions: call, return, passing parameters by (value, reference), passing arrays to function.
7. Recursion
8. Pointers: Pointers to functions, Arrays, Strings, Pointers to Pointers, Array of Pointers
9. Structures: Nested Structures, Pointers to Structures, Arrays of Structures and Unions.
10. Files: reading and writing, File pointers, file operations, random access, processor directives.
TOTAL: 60 PERIODS
COURSE OUTCOMES:

Upon completion of the course, the students will be able to


CO1: Demonstrate knowledge on C programming constructs.
CO2: Develop programs in C using basic constructs.
CO3: Develop programs in C using arrays.
CO4: Develop applications in C using strings, pointers, functions.
CO5: Develop applications in C using structures.
CO6: Develop applications in C using file processing.

TEXT BOOKS:

1. Reema Thareja, “Programming in C”, Oxford University Press, Second Edition, 2016.
2. Kernighan, B.W and Ritchie, D.M, “The C Programming language”, Second Edition, Pearson Education, 2015.
REFERENCES: 1. Paul Deitel and Harvey Deitel, “C How to Program with an Introduction to C++”, Eighth edition,
Pearson Education, 2018.
2. Yashwant Kanetkar, Let us C, 17th Edition, BPB Publications, 2020.
3. Byron S. Gottfried, "Schaum's Outline of Theory and Problems of Programming with C", McGraw-Hill Education,
1996. 4. Pradip Dey, Manas Ghosh, “Computer Fundamentals and Programming in C”, Second
5. Edition, Oxford University Press, 2013. 6. Anita Goel and Ajay Mittal, “Computer Fundamentals and Programming
in C”, 1st Edition, Pearson Education, 2013.
TABLE OF CONTENTS

SL. DATE NAME OF THE EXPERIMENT PAGE MARKS STAFF


NO NO. SIGNATURE
1 I/O STATEMENTS, OPERATORS, EXPRESSIONS.
A SOLVING QUADRATIC EQUATION
B FINDING BIGGEST AMOUNG TWO
NUMBERS USING TERNARY OPERATOR
C CONVERTING CENTIGRADE TO
FAHRENTHEIT
D SWAPPING OF TWO NUMBERS
2 DECISION-MAKING CONSTRUCTS: IF-ELSE, GOTO, SWITCH CASE
A CHECKING LEAP YEAR OR NOT
B BIGGEST AMONG TWO NUMBERS
C SIMULATING SIMPLE CALCULATOR
D PRINTING NUMBER DIGITS
E BIGGEST AMONG THREE NUMBERS
3 LOOPS: FOR, WHILE, DO-WHILE.
A SUM OF NATURAL NUMBERS
B ILLUSTRATION OF FOR GENERATING
FIBONACCI SERIES
C ILLUSTRATION OF WHILE CHECKING
PALINDROME NUMBER OR NOT
D THE GIVEN NUMBER IS ARMSTRONG
NUMBER OR NOT
E THE GIVEN NUMBER IS PRIME OR NOT
4 ARRAYS: 1D AND 2D, MULTI- DIMENSIONAL ARRAYS, TRAVERSAL.
A COMPUTING MEAN VALLUE OF
N NUMBERS
B SORTING OF N NUMBERS
C ADDITION OF TWO MATRICES
D MULTIPLICATIONS OF TWO
MATRICES
E LINEAR SEARCH
F BINARY SEARCH
SL. DATE NAME OF THE EXPERIMENT PAGE MARKS STAFF
NO NO. SIGNATURE
5 STRINGS: OPERATIONS. STRING IS
PALINDROME OR NOT
6 CALL, RETURN, PASSING PARAMETERS BY (VALUE, REFERENCE),
PASSING ARRAYS TO FUNCTION.
A FINDING MAX OF THREE NUMBER USING
FUNCTION
B SWAPPING TWO NUBERS USING PASS BY
VALUE
C SWAPPING TWO NUMBERS USING PASS BY
REFERENCE
7 RECURSION. FACTORIAL OF GIVEN
NUMBER USING RECURSIVE FUNCTION
8 POINTERS TO FUNCTIONS, ARRAYS, STRINGS, POINTERS TO POINTERS, ARRAY OF
POINTERS.
A POINTERS TO FUNCTIONS - CALCULATING
AREA OF A TRIANGLE
B POINTERS & ARRAYS FINDING MEAN OF N
NUMBERS USING ARRAYS
9 STRUCTURES: NESTED STRUCTURES, POINTERS TO STRUCTURES, ARRAYS OF
STRUCTURES
A NESTED STRUCTURES: PRINTING
EMPLOYEE PERSONAL DETAILS
B POINTERS TO STRUTURES :PRINTING
STUDENT DETAILS
C ARRAY OF STRUCTURES: CALCULATING
STUDENT MARK DETAILS
10 FILES: READING AND WRITING, FILE POINTERS, FILE OPERATIONS, RANDOM
ACCESS, PROCESSOR DIRECTIVES
A READING AND WRITING FILE
B PROGRAM TO COUNT THE NUMER OF
CHARACTERS AND NUMBER OF LINES IN
A FILE USING FILE POINTERS
C PROGRAM TO COPY ONE FILE TO
ANOTHER
D PROGRAM TO COMPUTE AREA OF CIRCLE
USING PREPROCESSOR DIRECTIVES
E PROGRAM TO COMPUTE ADDITION OF
TWO NUMBERS USING COMMAND LINE
ARGUMENTS
11 CONTENT BEYOND THE SYLLABUS- LINEAR DATA STRUCTURES
A SINGLY LIKNED LIST IMPLEMENTATION
B STACK IMPLEMENTATION
C QUEUE IMPLEMENTATION
EX NO: 1A
DATE: SOLVING QUADRATIC EQUATION

Objective:

To develop a C program to find the roots of a quadratic equation, to understand mathematical functions
in C language using quadratic equation, Quadratic equations are used in physics, engineering, and
graphics and this problem builds foundational skills for such domains

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers
Pre-requisite Knowledge:

Basic structure of C program


Arithmetic operations: addition, subtraction, multiplication, division
Order of operations (BODMAS rule)
Understanding of variables, constants, and equations
Input/output functions
Mathematical functions in c

Theory / Concept Overview:


A quadratic equation has the standard form:
ax² + bx + c = 0
Where a ≠ 0. The roots of the quadratic equation are given by the formula:

• The expression b² - 4ac is called the discriminant (D):


o If D > 0: two real and distinct roots
o If D = 0: two real and equal roots
o If D < 0: two complex conjugate roots
Problem Statement:

Write a C program to input coefficients a, b, and c, and compute the roots of the quadratic equation. Display
the nature of roots and the calculated value
Algorithm:
Step 1: Start
Step 2: Read the coefficients of the equation, a, b and c from the user.
Step 3: Calculate discriminant = (b * b) – (4 * a * c)
Step 4: If discriminant > 0:
Calculate root1 = ( -b + sqrt(discriminant)) / (2 * a)
Calculate root2 = ( -b - sqrt(discriminant)) / (2 * a)
Display "Roots are real and different"
Display root1 and root2
Step 5: Else if discriminant = 0:
Calculate root1 = -b / (2 *a)
root2 = root1
Display "Root are real and equal"
Display root1 and root2
Step 6: Else:
Calculate real = -b / (2 * a)
Calculate imaginary = sqrt(-discriminant) / (2 * a)
Display “Roots are imaginary”
Display real, "±" , imaginary, "i"
Step 7: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Enter the values of a b c: 1 4 3
The real roots = -3.000000 -5.000000
Test Case 2:
Enter the values of a b c: 1 2 1
Roots are equal =-1.000000 -1.000000
Test Case 3:
Enter the values of a b c: 1 1 4
Roots are imaginary

Result:

The program successfully finds roots of quadratic equation for the given input.

Viva Questions:

1. What is a quadratic equation?


2. What is the formula for finding the roots of a quadratic equation?
3. What is a discriminant? What does it signify?
4. What happens when a = 0 in a quadratic equation?
5. How are complex roots represented in programming?
6. Can the sqrt() function handle negative inputs in C?
7. Why do we check the value of the discriminant?
8. What would happen if we didn't handle the complex root case separately?

Grade / Mark:

Staff Signature:
EX NO: 1B FINDING BIGGEST AMOUNG TWO NUMBERS USING TERNARY OPERATOR
DATE:

Objective:

To develop a C program that uses the ternary (conditional) operator to compare two numbers and determine
the larger of the two. This enhances the understanding of decision-making constructs and introduces concise
syntax alternatives to if-else statements.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers
Pre-requisite Knowledge:
Basic structure of C program
Variables and Data Types
Input and Output Functions
Ternary (Conditional) Operator
o Syntax: condition ? value_if_true : value_if_false;
o Used for decision making as a short form of if-else.
Operators and Expressions
Basic Logic and Comparison
Theory / Concept Overview:

To find the largest of two numbers, programmers typically use a decision-making construct. While if-else is
common, the ternary operator offers a more compact and readable alternative for simple decisions.
Ternary Operator in C
The ternary operator (also called the conditional operator) is a shortcut for if-else statements.
Its syntax is:
condition ? expression_if_true : expression_if_false;
It evaluates the condition:
• If the condition is true, it executes expression_if_true.
• If the condition is false, it executes expression_if_false.
Problem Statement:

Write a C program to input two numbers from the user and find the biggest among them using the ternary
operator.

Algorithm:
Step 1: Start.
Step 2: Read two numbers A and B.
Step 3: Check C= (A>B)? A:B. That is if A is bigger than B then C=A otherwise C=B.
Step 4: Print bigger value as C.
Step 5: Stop.

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Enter the first number: 10
Enter the second number: 20
The largest number is: 20
Test Case 2:
Enter the first number: 100
Enter the second number: 20
The largest number is: 100
Test Case 3:
Enter the first number: 10
Enter the second number: 200
The largest number is: 200

Result:

The program successfully finds biggest among two numbers using ternary operator for the given input.

Viva Questions:
.
1. What is a ternary operator?.
2. What is the syntax of the ternary operator in C?
3. What is the associativity of the ternary operator?
4. Can you nest ternary operators?
5. What happens if both numbers are equal?
6. Can you use ternary operator for float or char values?
7. Is the ternary operator mandatory for this task?
8. What are the benefits of using ternary operators?

Grade / Marks:

Staff Signature:
EXNO:1C CONVERTING CENTIGRADE TO FAHRENTHEIT
DATE:

Objective:

To develop a C program that takes temperature in Celsius (Centigrade) as input from the user and converts it
to Fahrenheit using the standard mathematical formula. This program helps to understand user input,
arithmetic operations, and basic C syntax.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

Basic structure of C program


Variables and Data Types
Input and Output Functions
Arithmetic Operations
Mathematical Function in C

Theory / Concept Overview:

Temperature can be measured in various units, such as Celsius (Centigrade) and Fahrenheit. In many
applications, it's important to convert between these units.
Celsius to Fahrenheit Conversion
The standard mathematical formula to convert temperature from Celsius to Fahrenheit is:
Fahrenheit=(Celsius×95)+32
This formula increases the Celsius value by a scaling factor (9/5 ≈ 1.8) and then shifts it by 32 units to align
with the Fahrenheit scale.
Problem Statement:

Write a C program that reads a temperature value in Centigrade (Celsius) from the user and converts it to
Fahrenheit using the standard conversion formula

Algorithm:
Step 1:Start.
Step 2:Read centigrade value C. 3. Calculate F=C*(9/5)+32
Step 3:Print Fahrenheit value F.
Step 4:Stop.
Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Enter temperature in Celsius: 0
Temperature in Fahrenheit: 32.00Test Case 2:
Enter temperature in Celsius: 37
Temperature in Fahrenheit: 98.60
Test Case 3:
Enter temperature in Celsius: -10
Temperature in Fahrenheit: 14.00

Result:

The program successfully converts centigrade to Fahrenheit.

Viva Questions:
1.Which data type is used for temperature values? Why?
2.Why do we use 9.0 / 5.0 instead of 9 / 5?
3.What happens if the user enters a negative temperature?
4.Can we use double instead of float? What's the difference?
5.What function is used to take user input in C?
6.What function is used to display output in C?

Grade / Marks:

Staff Signature:
EXNO:1D SWAPPING OF TWO NUMBERS
DATE:

Objective:

To develop a C program for swapping of two numbers. The objective of swapping two numbers using a C
program is to exchange the values of two variables so that the value of the first variable becomes the value
of the second, and vice versa.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:
Basic structure of C program
Variables and Data Types
Input and Output Functions
Arithmetic Operations
Concept of Memory Storage

Theory / Concept Overview:

Swapping of two numbers is a fundamental concept in programming, especially in C, where we exchange the
values of two variables. This is a key building block in many algorithms such as sorting, searching, and data
manipulation.
What is Swapping?
Swapping means interchanging the values stored in two variables.
If:
Before Swap: a = 5, b = 10
After Swap: a = 10, b = 5
Problem Statement:

Write a C program to swap the values of two variables entered by the user. The program should display the
values before and after swapping.

Algorithm :
Step 1: Start
Step 2 : Declare three integer variables: a, b, and temp
Step 3:Read the values of a and b from the user
Step 4:Display the values of a and b before swapping
Step 5:Swap the values using a temporary variable:
temp = a
a=b
b = temp
Step 6: Display the values of a and b after swapping
Step 7:Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1: Test Case 2: Test Case 3:


Enter the value of a: 15 Enter the value of a: 5 Enter the value of a: 515
Enter the value of b: 30 Enter the value of b: 3 Enter the value of b: 300
Before Swapping: Before Swapping: Before Swapping:
a = 15 a=5 a = 515
b = 30 b=3 b = 300
After Swapping: After Swapping: After Swapping:
a = 30 a=3 a = 300
b = 15 b=5 b = 515

Result:

The program successfully swaps two given numbers.

Viva Questions:
1. What is swapping in programming?
2. Why do we need to swap values in programs?
3. What are the different ways to swap two numbers in C?

Grade / Marks:

Staff Signature:
EXPNO: 2A CHECKING LEAP YEAR OR NOT
DATE:

Objective:

To develop a C program to check the given year is leap year or not, based on the defined conditions, and
helps students understand conditional statements, logical operators, and control flow in C programming.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

Basic structure of C program


Variables and Data Types
Input and Output Functions
Conditional Statements
Modulus Operator %
Logical Operators
Understanding Leap Year Rules
• A year is a leap year if: Divisible by 4 and not divisible by 100Or divisible by 400

Theory / Concept Overview:


A leap year is a year that has 366 days instead of 365, with an extra day (February 29). Leap years exist to
correct the mismatch between the calendar year (365 days) and the astronomical year (approximately 365.242
days).
Leap Year Rules (Gregorian Calendar)
To determine if a year is a leap year, the following rules apply:
1. If the year is divisible by 4, go to step 2. Otherwise, it's not a leap year.
2. If the year is divisible by 100, go to step 3. Otherwise, it is a leap year.
3. If the year is divisible by 400, then it is a leap year. Otherwise, it is not.
Problem Statement:

Write a C program to check whether a given year is a leap year or not based on the rules of the Gregorian
calendar. The program should take a year as input from the user and display whether it is a leap year or not
a leap year.

Algorithm:
Step 1: Start
Step 2: Read year
Step 3: Check whether year is divisible by 4 and 400 and not divisible by 100.
Step 4: If the condition is true then print year is leap year. Otherwise print year is not leap year.
Step 5: Stop.

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Enter the Value of N: 2000
2000 is a leap year.
Test Case 2:
Enter the value of N: 1700
1700 is not leap year.
Test Case 3:
Enter the value of N: 2024
2024 is a leap year.

Result:

The program successfully checks the given year is leap year or not.

Viva Questions:
1.What is a leap year?
2.Which operators are used to check leap year conditions in C?
3.Which conditional statement is used in the program?
4.What is the use of the modulus operator (%) in this program?

Grade / Marks:

Staff Signature:
EXPNO: 2B BIGGEST AMONG TWO NUMBERS
DATE:

Objective:

To develop a C program to check biggest among two numbers. C program that compares two numbers
entered by the user and determines the larger (biggest) number among them using conditional logic.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

Basic structure of C program


Variables and Data Types
Input and Output Functions
Conditional Statements
Relational Operators
Logical Thinking

Theory / Concept Overview:

Comparing two numbers to find the biggest (larger) value is one of the most basic yet important tasks in
programming. It involves taking two inputs, using relational and conditional operators, and displaying the
larger of the two values.
Relational Operators
Conditional Statements (if-else)
Input/Output Handling
Logic for Comparing Two Numbers
Problem Statement:

Write a C program to read two numbers entered by the user and determine which one is the biggest
(greater). The program should then display the biggest number. If both numbers are equal, it should display
a message stating that they are equal.

Algorithm:
Step 1: Start.
Step 2: Read two numbers a, b.
Step 3: If a>b then go to greater. Otherwise print B is greater than A.
Step 4: In greater section print A is greater than B.
Step 5: Stop.

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Enter two numbers 45 12
A is greater than B
Test Case 2:
Enter two numbers 45 97
B is greater than A
Test Case 3:
Enter two numbers 450 197
B is greater than A

Result:

The program successfully checks biggest among two numbers.

Viva Questions:
1. What is the objective of this program?
2. What is a relational operator?
3. Which relational operator is used to find the bigger number?
4. What happens if both numbers are equal?

Grade / Marks:

Staff Signature:
EXPNO: 2C SIMULATING SIMPLE CALCULATOR
DATE:

Objective:
To develop a C program that simulates a simple calculator which performs basic arithmetic operations (+, −,
×, ÷) based on user input. This program enhances understanding of:
• Arithmetic operators
• Conditional and switch-case statements
• Control flow and user interaction

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Variables and data types


• Input and output in C
• Arithmetic operators (+, -, *, /)
• switch-case or if-else statements
• Control flow and user interaction using scanf and printf

Theory / Concept Overview:

A simple calculator performs basic arithmetic operations (addition, subtraction, multiplication, and
division). In this C Flowchart :
• The user provides two numbers and an operator.
• Based on the operator, the correct operation is performed using a switch or if-else.
• Special care is taken for division, especially division by zero.
Problem Statement:

Write a C program that takes two numbers and an *operator (+, -, , /) as input from the user and displays the
result of the operation.

Algorithm :

Step 1: Start
Step 2: Input two numbers and an operator
Step 3: Use switch-case or if-else to check the operator
Step 4: Perform the appropriate operation:
- '+' for addition
- '-' for subtraction
- '*' for multiplication
- '/' for division (check for division by zero)
Step 5: Display the result
Step 6: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Enter an operator (+, -, *, /): +
Enter two operands: 10 20
Result: 30.00
Test Case 2:
Enter an operator (+, -, *, /): /
Enter two operands: 15 3
Result: 5.00
Test Case 3 (Error Case):
Enter an operator (+, -, *, /): /
Enter two operands: 15 0
Error: Division by zero is not allowed.
Result:

The program correctly performs arithmetic operations based on the selected operator and handles invalid
input like division by zero.
Viva Questions:

1. What is a switch-case statement?


2. Why is division by zero not allowed?
3. What data types are used in this program?
4. Can we use if-else instead of switch? Why or why not?
5. What happens if the user enters an invalid operator?

Grade / Marks:

Staff Signature:
EXPNO: 2D PRINTING NUMBER DIGITS
DATE:

Objective:

To develop a C program that reads an integer and prints each digit of the number in words using switch
statements. This helps students understand digit extraction, the use of switch-case control structures, and
working with loops.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:
• Basic structure of a C program
• Loops (while)
• Modulus (%) and division (/) operators
• switch-case statements
• Input and output using scanf and printf

Theory / Concept Overview:

To print the digits of a number in words (e.g., 123 → One Two Three), we need to extract each digit.
To print them in left to right order:
1. First reverse the number (because digit extraction gives digits from right to left).
2. Then process each digit using a switch statement to map digits (0–9) to their respective words.

Problem Statement:
Write a C program that reads an integer number from the user and prints each digit in words using switch
statements.
Algorithm:

Step 1: Start
Step 2: Read an integer number from the user
Step 3: If number is 0, print "Zero" and stop
Step 4: Reverse the number to process digits from left to right
Step 5: While reversed number is not 0:
→ Extract digit using % 10
→ Use switch-case to print digit in word
→ Remove last digit using / 10
Step 6: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Enter a number: 120
Digits in words: One Two Zero
Test Case 2:
Enter a number: 5067
Digits in words: Five Zero Six Seven
Test Case 2
Enter a number: 50
Digits in words: Five Zero

Result:
The program successfully prints the digits of a number in words using switch-case statements and control
flow logic.

Viva Questions:
1. What is the purpose of the switch statement in this program?
2. Why do we reverse the number before printing its digits?
3. What happens if the number entered is 0?
4. How do you extract the last digit of a number?
5. How does integer division (/) help in removing digits?
6. Can we use if-else instead of switch?
7. What is the output for input 1000? Why?
8. How would you modify the program to handle negative numbers?
9. What are the limitations of this program?
10. Can float numbers be used in this program? Why or why not?

Grade / Marks:

Staff Signature:
EXPNO: 2E BIGGEST AMONG THREE NUMBERS
DATE:

Objective:
To develop a C program that takes three numbers as input and determines which one is the largest. This
helps students understand conditional statements (if, else if, else), comparison operators, and basic control
structures in C.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Basic structure of a C program


• Input/output functions (scanf, printf)
• Variables and data types
• Comparison operators (>, <)
• Conditional statements (if, else if, else)

Theory / Concept Overview:

To determine the largest among three numbers, we compare:


• First with second and third
• Second with first and third
• Third with first and second
This is done using if-else ladder or nested if statements. The comparison operators help evaluate which
number is greater.

Problem Statement:

Write a C program that reads three numbers from the user and prints the largest among them.
Algorithm:

Step 1: Start
Step 2: Read three numbers (a, b, c)
Step 3: If (a > b) and (a > c), then a is the largest
Step 4: Else if (b > a) and (b > c), then b is the largest
Step 5: Else, c is the largest
Step 6: Print the largest number
Step 7: Stop

Program Logic:
Flowchart:
Sample Input/Output:
Test Case 1:
Enter three numbers:
10 25 15
25 is the largest number.
Test Case 2:
Enter three numbers:
50 50 40
50 is the largest number.
Test Case 3:
Enter three numbers:
-5 -1 -10
-1 is the largest number.

Result:
The program successfully finds and displays the biggest number among the three inputs using conditional
logic.

Viva Questions:

1. Which conditional statement is used in this program?


2. What are the comparison operators used?
3. What happens if all three numbers are equal?
4. Can we use the ternary operator for this logic?
5. How does if-else if help in multiple condition checking?
6. What is the difference between > and >=?
7. Can we use switch statements for this program? Why or why not?
8. What is the time complexity of this comparison logic?
9. What happens if the input contains negative numbers?
10. How would you modify the program to find the smallest number?

Grade / Marks:

Staff Signature:
EXPNO: 3A SUM OF NATURAL NUMBERS
DATE:

Objective:

To develop a C program that calculates the sum of the first n natural numbers using a for loop. This helps
students understand the use of loops, accumulation variables, and iterative control structures in C.
Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Structure of a C program
• Declaring and using variables
• Input and output functions (scanf, printf)
• for loop syntax and structure
• Natural numbers (positive integers starting from 1)

Theory / Concept Overview:

Natural numbers are a sequence of positive integers starting from 1 (i.e., 1, 2, 3, 4, ...).
The sum of first n natural numbers can be calculated:
• Using a loop (iterative method)
• Or using the formula: sum = n * (n + 1) / 2 (not used here)
This program uses a for loop to add numbers from 1 to n one by one.

Problem Statement:
Write a C program that takes a positive integer n as input from the user and calculates the sum of the first n
natural numbers using a for loop.
Algorithm:
Step 1: Start
Step 2: Declare variables: n, sum = 0
Step 3: Read the value of n
Step 4: For i from 1 to n:
Add i to sum
Step 5: Print the value of sum
Step 6: Stop

Program Logic:
Flowchart:
Sample Input/Output:
Test Case 1:
Enter a positive integer: 5
Sum of first 5 natural numbers = 15
Test Case 2:
Enter a positive integer: 10
Sum of first 10 natural numbers = 55
Test Case :3
Enter a positive integer: 3
Sum of first 10 natural numbers = 6

Result:
The program successfully calculates and displays the sum of the first n natural numbers using a for loop.

Viva Questions:
1. What is a for loop in C?
2. What is the difference between for and while loop?
3. What is the purpose of the sum variable in this program?
4. What will be the output if n is 0 or negative?
5. How can the same result be achieved without using a loop?
6. What is the formula to calculate the sum of first n natural numbers?
7. What is the data type of the variables used?
8. Can this program be written using a while loop?
9. Why do we initialize sum to 0?
10. What are natural numbers?

Grade / Marks:

Staff Signature:
EXPNO: 3B ILLUSTRATION OF FOR GENERATING FIBONACCI SERIES
DATE:

Objective:
To develop a C program that generates and displays the Fibonacci series up to n terms
using a for loop. This helps students understand looping structures, sequence generation,
and variable updates in iterative processes.

Software/Hardware Requirements:
Hardware Minimum Requirement
Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:
• Basics of C programming
• Use of for loop
• Understanding variables and data types
• Concept of sequence generation
• Fibonacci series logic

Theory / Concept Overview:


The Fibonacci series is a sequence of numbers where each number is the sum of the two
preceding ones.
The series starts as:
0, 1, 1, 2, 3, 5, 8, 13, ...
Mathematically:
• F(0) = 0
• F(1) = 1
• F(n) = F(n-1) + F(n-2) for n ≥ 2
This program uses a for loop to calculate the terms iteratively by storing and updating
previous values.
Problem Statement:
Write a C program to generate the Fibonacci series up to n terms using a for loop. The
user should input the number of terms, and the program should display the series
accordingly.
Algorithm :
Step 1: Start
Step 2: Read number of terms (n)
Step 3: Initialize a = 0, b = 1
Step 4: Print a and b
Step 5: Loop from i = 3 to n:
next = a + b
print next
update a = b, b = next
Step 6: Stop
Program Logic:
Flowchart:
Sample Input/Output:
Test Case 1:
Enter the number of terms: 7
Fibonacci Series: 0 1 1 2 3 5 8
Test Case 2:
Enter the number of terms: 1
Fibonacci Series: 0
Test Case 3:
Enter the number of terms: 3
Fibonacci Series: 011

Result:
The program successfully generates and prints the Fibonacci series up to the specified
number of terms using a for loop.

Viva Questions:
1. What is the Fibonacci series?
2. Which looping construct is used in the program?
3. Why do we initialize a = 0 and b = 1?
4. How are the next terms calculated in the loop?
5. What is the time complexity of generating the Fibonacci series?
6. Can we use while or do-while instead of for?
7. What happens if the user enters 0 or a negative number?
8. What data types are used and why?
9. Can this program be modified to print Fibonacci numbers below a certain value
instead of number of terms?
10. How would you implement the Fibonacci series using recursion?

Grade / Marks:

Staff Signature:
EXPNO: 3C ILLUSTRATION OF WHILE CHECKING PALINDROME NUMBER OR NOT
DATE:

Objective:

To develop a C program that checks whether a given number is a palindrome using a while loop. This
enhances understanding of looping constructs, number manipulation, and logical decision-making in C.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:
• Basic structure of C program
• Variables and data types
• Input/output in C
• Use of while loop
• Arithmetic operations: division (/) and modulus (%)
• Concept of a palindrome

Theory / Concept Overview:


A palindrome number is a number that reads the same backward as forward.
Examples:
• 121 → Palindrome
• 123 → Not a Palindrome
• 909 → Palindrome
To check this, reverse the digits of the number and compare it with the original.

Problem Statement:

Write a C program that uses a while loop to check whether a given number is a palindrome. The program
should take an integer as input and display whether it is a palindrome or not.
Algorithm:

Step 1: Start
Step 2: Read number from user and store in variable 'num'
Step 3: Store original number in a temp variable
Step 4: Initialize reverse = 0
Step 5: Repeat while num > 0:
digit = num % 10
reverse = reverse * 10 + digit
num = num / 10
Step 6: Compare reverse with original
If equal, print "Palindrome"
Else, print "Not Palindrome"
Step 7: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Enter a number: 121
121 is a Palindrome number.
Test Case 2:
Enter a number: 345
345 is NOT a Palindrome number.
Test Case 3:
Enter a number: 9009
9009 is a Palindrome number.

Result:

The program successfully checks whether a given number is a palindrome using a while loop.

Viva Questions:
1. What is a palindrome number?
2. What looping construct is used in this program?
3. What does the modulus operator % do in this program?
4. Why do we store the original number before the loop?
5. Can this logic work for strings or characters?
6. What would happen if we don't store the original number in a temporary variable?
7. How would you modify the code to check for palindrome in a string?
8. Can this program work for negative numbers? Why or why not?
9. What is the purpose of reverse = reverse * 10 + digit?
10. How is integer division useful in this logic?

Grade / Marks:

Staff Signature:
EXPNO: 3D THE GIVEN NUMBER IS ARMSTRONG NUMBER OR NOT
DATE:

Objective:

To develop a C program that checks whether a given number is an Armstrong number, helping students
understand loops, arithmetic operations, and control flow in C.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Basics of C programming
• Loops (while or for)
• Arithmetic operators (%, /, *)
• Understanding of number systems
• Functions and variables

Theory / Concept Overview:

An Armstrong number (also known as narcissistic number) is a number that is equal to the sum of its
digits each raised to the power of the number of digits.
Example:
• 153 → 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 → Armstrong
• 9474 → 9⁴ + 4⁴ + 7⁴ + 4⁴ = 9474 → Armstrong
• 123 → Not Armstrong

Problem Statement:

Write a C program to check whether a given number is an Armstrong number. The program should
accept an integer input from the user and output whether the number is an Armstrong number or not.
Algorithm :

Step 1: Start
Step 2: Read a number and store in variable num
Step 3: Copy num into a temporary variable temp
Step 4: Count the number of digits (n)
Step 5: Initialize sum = 0
Step 6: Repeat until temp becomes 0:
a. digit = temp % 10
b. sum = sum + (digit ^ n)
c. temp = temp / 10
Step 7: If sum == num, then it is an Armstrong number
Else, it is not an Armstrong number
Step 8: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Enter a number: 153
153 is an Armstrong number.
Test Case 2:
Enter a number: 9474
9474 is an Armstrong number.
Test Case 3:
Enter a number: 123
123 is NOT an Armstrong number.

Result:

The program correctly checks whether the given number is an Armstrong number or not using loops and
arithmetic operations.

Viva Questions:

1. What is an Armstrong number?


2. How is the power operation performed in this program?
3. Which library function is used for exponentiation in C?
4. Why do we need to count the number of digits first?
5. What happens if the input is 0 or 1? Are they Armstrong numbers?
6. Can this program be written without using the math.h library?
7. What is the time complexity of this algorithm?
8. How would you modify the program to list all Armstrong numbers between 1 and 1000?
9. What data type is best for large numbers in Armstrong check?
10. Why do we use a temporary variable to store the original number?

Grade / Marks:

Staff Signature:
EXPNO: 3E THE GIVEN NUMBER IS PRIME NUMBER OR NOT
DATE:

Objective:
To develop a C program that checks whether a given number is prime or not, helping students understand
loops, conditional statements, and number theory in C programming.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:
• Variables and Data Types in C
• Loops (for, while)
• Conditional statements (if, else)
• Modulus operator %
• Prime number concept from mathematics

Theory / Concept Overview:


A prime number is a number greater than 1 that has only two factors: 1 and itself.
Examples of prime numbers: 2, 3, 5, 7, 11, 13, 17…
Note: 1 is not a prime number.
To check if a number is prime:
• Try dividing the number by all integers from 2 to √n.
• If it is divisible by any, it is not a prime.

Problem Statement:
Write a C program that takes an integer input from the user and checks whether the number is a prime
number or not.
Algorithm :
Step 1: Start
Step 2: Read the number (n)
Step 3: If n <= 1, it is not a prime number
Step 4: Repeat from i = 2 to i <= n/2
If n % i == 0, then it's not prime
Step 5: If no divisor is found, it is a prime number
Step 6: Stop

Program Logic:
Flowchart:
Sample Input/Output:
Test Case 1:
Enter a number: 7
7 is a Prime Number.
Test Case 2:
Enter a number: 10
10 is NOT a Prime Number.
Test Case 3:
Enter a number: 1
1 is NOT a Prime Number.

Result:
The program successfully checks whether a given number is prime or not using loops and conditional logic.

Viva Questions:
1. What is a prime number?
2. Is 1 a prime number? Why or why not?
3. Which loop is used in the program?
4. Why do we check up to n/2 or sqrt(n) instead of till n?
5. What is the purpose of the break statement in this program?
6. Can the same program be written using a while loop?
7. How would you modify the code to find all prime numbers up to a given limit?
8. What is the time complexity of this approach?
9. What is the role of the modulus operator (%)?
10. How can you improve this program's performance for large numbers?

Grade / Marks:

Staff Signature:
EXPNO: 4A COMPUTING MEAN VALLUE OF N NUMBERS
DATE:

Objective:

To develop a C program that computes the mean (average) of N numbers using


arrays. This program helps students understand array handling, loops, arithmetic
operations, and control flow in C programming.
Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:
• Declaration and initialization of arrays in C
• Input/output functions in C (scanf, printf)
• Looping constructs (for, while)
• Arithmetic operators (+, /)
• Concepts of average (mean = sum / number of elements)

Theory / Concept Overview:

The mean (average) of a list of numbers is obtained by:


Mean=Sum of all numbersCount of numbers (N)\text{Mean} = \frac{\text{Sum
of all numbers}}{\text{Count of numbers
(N)}}Mean=Count of numbers (N)Sum of all numbers
In this program, we:
• Read N numbers from the user into an array
• Sum all elements of the array using a loop
• Divide the sum by N to get the mean

Problem Statement:
Write a C program to read N numbers from the user, store them in an array,
compute the mean, and display the result.
Algorithm :

Step 1: Start
Step 2: Declare an array and variables (sum, mean, i, n)
Step 3: Read the number of elements (n)
Step 4: Loop to read n elements into the array
Step 5: Loop to calculate the sum of array elements
Step 6: Compute mean = sum / n
Step 7: Print mean
Step 8: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Enter the number of elements: 5
Enter number 1: 10
Enter number 2: 20
Enter number 3: 30
Enter number 4: 40
Enter number 5: 50
Mean (Average) of the numbers = 30.00
Test Case 2:
Enter the number of elements: 3
Enter number 1: 5
Enter number 2: 10
Enter number 3: 15
Mean (Average) of the numbers = 10.00

Result:

The program successfully computes and displays the mean value of N user-
provided numbers using an array.

Viva Questions:

1. What is the purpose of using an array in this program?


2. What is the formula for calculating mean?
3. Which data type is used to store mean? Why?
4. Can we calculate the mean without using an array?
5. What happens if n is 0? How can we handle it?
6. What is the difference between float and int when calculating mean?
7. What is the time complexity of this program?
8. What would be the output if all values entered are zero?
9. Why is %f used in scanf/printf instead of %d?
10. What is the maximum number of elements this program can handle?

Grade / Marks:

Staff Signature:
EXPNO: 4B SORTING OF N NUMBERS
DATE:

Objective:
To develop a C program that reads N numbers from the user, stores them in an
array, and sorts them in ascending order. This exercise helps students
understand array manipulation, comparison logic, and implementation of
sorting algorithms like Bubble Sort.

Software/Hardware Requirements:
Hardware Minimum Requirement
Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Array declaration and initialization


• Looping constructs (for, while)
• Conditional statements (if, else)
• Swapping two variables using a temporary variable
• Basic understanding of Bubble Sort or similar sorting algorithms

Theory / Concept Overview:

Sorting is the process of arranging data in a particular format. The most


common formats are ascending or descending order.
In this program, we'll use Bubble Sort, which works as follows:
• Repeatedly compare adjacent elements
• Swap them if they are in the wrong order
• Continue this process until the array is sorted

Problem Statement:

Write a C program to read N numbers from the user and sort them in ascending
order using a sorting algorithm (Bubble Sort).
Algorithm :

Step 1: Start
Step 2: Read the number of elements (n)
Step 3: Read n elements into an array
Step 4: Use nested loops to compare and swap adjacent elements
Step 5: Continue until array is sorted
Step 6: Display the sorted array
Step 7: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Enter number of elements: 5
Enter number 1: 40
Enter number 2: 10
Enter number 3: 50
Enter number 4: 20
Enter number 5: 30
Sorted numbers in ascending order:
10 20 30 40 50
Test Case 2:
Enter number of elements: 5
Enter number 1: 4
Enter number 2: 1
Enter number 3: 5
Enter number 4: 2
Enter number 5: 3
Sorted numbers in ascending order:
12 3 4 5

Result:

The program successfully sorts the N user-input numbers in ascending order


and displays them.

Viva Questions:

1. What is the purpose of sorting?


2. What sorting technique is used in this program?
3. Explain how Bubble Sort works.
4. What is the time complexity of Bubble Sort?
5. How do you swap two numbers in C?
6. Can you modify the program to sort in descending order?
7. What will happen if the array is already sorted?
8. What changes are required to implement Selection Sort instead?
9. What is the space complexity of Bubble Sort?
10. What is the worst-case input for Bubble Sort?

Grade / Marks:

Staff Signature:
EXPNO: 4C ADDITION OF TWO MATRICES
DATE:

Objective:

To develop a C program that adds two matrices and displays the resulting matrix. This program helps
students understand multi-dimensional arrays, nested loops, and basic matrix operations.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Arrays and multi-dimensional arrays


• Loops (especially nested for loops)
• Reading and printing values using scanf() and printf()
• Basic understanding of matrix operations

Theory / Concept Overview:


Matrix addition involves adding corresponding elements from two matrices of the same size.
If A and B are two matrices, then the sum matrix C is defined as:
C[i][j] = A[i][j] + B[i][j]
This operation is only valid when the dimensions of both matrices are equal.

Problem Statement:

Write a C program that takes two matrices of the same dimensions as input from the user, adds them, and
prints the resultant matrix.
Algorithm:

Step 1: Start
Step 2: Read the number of rows and columns
Step 3: Read the first matrix elements
Step 4: Read the second matrix elements
Step 5: Add corresponding elements and store in result matrix
Step 6: Display the result matrix
Step 7: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1: Test Case 2:


Enter number of rows: 2 Enter number of rows: 2
Enter number of columns: 2 Enter number of columns: 2
Enter elements of first matrix: Enter elements of first matrix:
a[0][0]: 1 a[0][0]: 2
a[0][1]: 2 a[0][1]: 2
a[1][0]: 3 a[1][0]: 2
a[1][1]: 4 a[1][1]: 2
Enter elements of second matrix: Enter elements of second matrix:
b[0][0]: 5 b[0][0]: 2
b[0][1]: 6 b[0][1]: 2
b[1][0]: 7 b[1][0]: 2
b[1][1]: 8 b[1][1]: 2
Resultant matrix after addition: Resultant matrix after addition:
6 8 4 4
10 12 4 4

Result:
The program successfully adds two matrices and prints the resultant matrix.

Viva Questions:

1. What is a matrix?
2. When can two matrices be added?
3. What is the syntax to declare a 2D array in C?
4. Why do we use nested loops for matrix operations?
5. What will happen if matrices have different dimensions?
6. Can we perform matrix addition using a single loop?
7. What is the time complexity of matrix addition?
8. How do we access elements in a 2D array?
9. What is the use of \t in the output format?
10. How can you modify this program for matrix subtraction?

Grade / Marks:

Staff Signature:
EXPNO: 4D MULTIPLICATIONS OF TWO MATRICES
DATE:

Objective:

To develop a C program that multiplies two matrices and displays the result. This helps students understand
multi-dimensional arrays, nested loops, and the matrix multiplication algorithm in C programming.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Arrays and multi-dimensional arrays


• Nested for loops
• Matrix multiplication concept
• Reading and printing values using scanf() and printf()

Theory / Concept Overview:

Matrix multiplication is only possible when number of columns in the first matrix = number of rows in the
second matrix.
If matrix A is of size m x n and matrix B is of size n x p, the resulting matrix C will be of size m x p, where:
markdown
C[i][j] = A[i][0]*B[0][j] + A[i][1]*B[1][j] + ... + A[i][n-1]*B[n-1][j]

Problem Statement:

Write a C program to read two matrices from the user, multiply them (if possible), and print the resulting
matrix.
Algorithm:

Step 1: Start
Step 2: Read dimensions of matrices A (m x n) and B (n x p)
Step 3: Read matrix A elements
Step 4: Read matrix B elements
Step 5: Multiply matrices using 3 nested loops
Step 6: Display the resulting matrix
Step 7: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test case 1: Test case 2:


Enter rows and columns of first matrix (A): 2 3 Enter rows and columns of first matrix (A):3 3
Enter rows and columns of second matrix (B): 3 2 Enter rows and columns of second matrix (B): 3 3
Enter elements of matrix A: Enter elements of matrix A:
123 333
456 333
Enter elements of matrix B: 333
78 Enter elements of matrix B:
9 10 333
11 12 333
Output: 333
Resultant matrix after multiplication: Output:
58 64 Resultant matrix after multiplication:
139 154 27 27 27
27 27 27
27 27 27

Result:

The program successfully multiplies two matrices and displays the result if the dimensions are compatible.

Viva Questions:

1. What is the condition for matrix multiplication to be valid?


2. What is the time complexity of matrix multiplication?
3. How many loops are needed for matrix multiplication in C?
4. Can matrix multiplication be commutative? (i.e., A × B = B × A)
5. What is the size of the resultant matrix if A is m × n and B is n × p?
6. How is the result matrix initialized before multiplication?
7. Why do we use three nested loops in the program?
8. How can you optimize matrix multiplication?
9. Can you perform multiplication for non-square matrices?
10. What will happen if the multiplication condition is not met?

Grade / Marks:

Staff Signature:
EXPNO: 4E LINEAR SEARCH
DATE:

Objective:

To develop a C program that performs linear search on an array of elements to find the position of a
specified key element. This helps understand array traversal and searching algorithms in C.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Basic C syntax
• Arrays and loops
• Conditional statements (if, else)
• Input and output functions (scanf(), printf())

Theory / Concept Overview:

Linear search is the simplest searching algorithm. It checks each element in the array sequentially until the
desired element (key) is found or the end of the array is reached.
Time Complexity:
• Best Case: O(1)
• Average Case: O(n)
• Worst Case: O(n)

Problem Statement:
Write a C program to search for an element in a list of integers using the linear search technique. If found,
print its position; otherwise, display a not found message.
Algorithm :
Step 1: Start
Step 2: Input the number of elements (n) and the array elements
Step 3: Input the key element to be searched
Step 4: Traverse each element from index 0 to n-1
Step 5: If element at index i equals key, print position and stop
Step 6: If key not found, print "Not Found"
Step 7: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test case 1 :
Enter number of elements in array: 5
Enter 5 elements:
10 20 30 40 50
Enter the element to search: 30
Output:
Element 30 found at position 3
Test case 2 :
Enter number of elements in array: 5
Enter 5 elements:
10 200 30 400 500
Enter the element to search: 300
Output:
Element 300 not found

Result:

The program successfully performs linear search and displays the result based on whether the key is found
or not.

Viva Questions:
1. What is linear search?
2. What is the time complexity of linear search?
3. What are the best and worst-case scenarios?
4. Can linear search be used on unsorted arrays?
5. What is the difference between linear search and binary search?
6. Can we search for multiple occurrences of an element?
7. How can we optimize a linear search?
8. Why is the array index incremented by 1 in the output?
9. What happens if the array is empty?
10. What are the advantages and disadvantages of linear search?

Grade / Marks:

Staff Signature:
EXPNO: 4F BINARY SEARCH
DATE

Objective:
To write a C program to perform Binary Search on a sorted array and
understand the divide-and-conquer technique to find elements efficiently.

Software/Hardware Requirements:
Hardware Minimum Requirement
Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Understanding of arrays and loops in C


• Familiarity with functions and control statements (if, while, etc.)
• Concept of searching techniques: Linear vs Binary

Theory / Concept Overview:

• Binary Search is an efficient algorithm


• m to search for an element in a sorted array.
• It repeatedly divides the array in half to find the target value.
• Time Complexity: O(log n)
• Works only on sorted arrays

Problem Statement:

Write a C program to implement Binary Search.


Given a sorted array and a key, find whether the key is present in the array
using Binary Search.
Algorithm :

Step 1: Start with two indices: low = 0, high = size - 1


Step 2: Repeat:
o Find mid = (low + high) / 2
o If array[mid] == key, element is found
o If key < array[mid], search left half: high = mid - 1
o If key > array[mid], search right half: low = mid + 1
Step 3: If low > high, element not found
Step 4: Stop

Program Logic:
Flowchart:
Sample Input/Output:
Test Cases 1:
Enter number of elements: 5
Enter 5 sorted elements:
2 4 6 8 10
Enter element to search: 6
Element 6 found at position 3 (index 2).
Enter element to search: 9
Element 9 not found in the array.
Test Cases 1:
Enter number of elements: 5
Enter 5 sorted elements:
2 4 6 8 10
Enter element to search: 6
Element 6 found at position 3 (index 2).
Enter element to search: 9
Element 9 not found in the array.

Result:

The Binary Search program successfully finds the position of an element in a


sorted array or reports if it is not present.

Viva Questions:
1. What is binary search?
2. What is the prerequisite for using binary search?
3. What is the time complexity of binary search?
4. How does binary search differ from linear search?
5. Can binary search be used on unsorted arrays?
6. What is the worst-case scenario in binary search?
7. What happens if the element is not found?
8. Can binary search be implemented recursively?
9. How is mid value calculated in binary search?
10. What are real-world applications of binary search?

Grade / Marks:

Staff Signature:
EXPNO: 5 STRING IS PALINDROME OR NOT
DATE:

Objective:

To develop a C program that checks whether a given string is a palindrome or not. This helps students
understand string manipulation, loops, arrays, and conditional logic in C programming.

Software/Hardware Requirements:
Hardware Minimum Requirement
Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• C strings and character arrays


• Loops and conditional statements
• strlen() function from string.h
• Basic if-else logic
• Input/output using scanf() and printf()

Theory / Concept Overview:

A palindrome is a word, phrase, or sequence that reads the same backward as forward.
Examples: madam, level, radar, noon
To check for a palindrome:
• Reverse the string.
• Compare the reversed string with the original.
• If both are equal, it's a palindrome.

Problem Statement:

Write a C program that takes a string as input and checks if it is a palindrome or not, by comparing characters
from both ends of the string.
Algorithm :

Step 1: Start
Step 2: Input the string
Step 3: Find the length of the string
Step 4: Use a loop to compare the first and last characters moving toward the center
Step 5: If all pairs match, it’s a palindrome
Step 6: Otherwise, it’s not a palindrome
Step 7: Display result
Step 8: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Input: madam
Output: The string "madam" is a palindrome.
Test Case 2:
Input: hello
Output: The string "hello" is not a palindrome.
Test Case 3:
Input: liril
Output: The string "liril" is a palindrome.

Result:

The program successfully checks whether a given string is a palindrome by comparing characters from both
ends.

Viva Questions:

1. What is a palindrome?
2. Which function is used to find the length of a string in C?
3. Why do we use strlen() in this program?
4. How does the program compare characters?
5. Can this program work for sentences or spaces?
6. What data type is used for strings in C?
7. What will happen if the input is in uppercase?
8. How can we modify the program to ignore cases?
9. Can we check for numeric palindromes using this method?
10. What is the time complexity of this palindrome checking logic?

Grade / Marks:

Staff Signature:
EXPNO:6A FINDING MAX OF THREE NUMBER USING FUNCTION
DATE:

Objective:

To develop a C program that uses a user-defined function to find the maximum


among three numbers, helping students understand the concept of functions,
conditional logic, and function calls in C.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• C functions (definition, declaration, and calling)


• Input and output using scanf() / printf()
• Conditional statements (if, else if, else)
• Basic syntax of C language

Theory / Concept Overview:

A function is a block of code that performs a specific task.


This program uses a user-defined function to compare three integers and return the
largest among them.
Control is passed to the function with arguments (three numbers), and the result is
returned back using the return statement.

Problem Statement:

Write a C program that takes three numbers as input from the user and finds the
maximum of the three numbers using a user-defined function.
Algorithm:

Step 1: Start
Step 2: Define a function `maxOfThree(int a, int b, int c)`
Step 3: Inside the function, use if-else conditions to compare a, b, and c
Step 4: Return the largest number
Step 5: In main(), read three numbers from the user
Step 6: Call the function and print the result
Step 7: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Input: 10 25 15
Output: The maximum number is: 25
Test Case 2:
Input: 8 3 8
Output: The maximum number is: 8
Test Case 3:
Input: -5 -10 -2
Output: The maximum number is: -2

Result:

The program successfully determines the largest of three numbers using a function.

Viva Questions:

1. What is a function in C?
2. What is the return type of the function used in this program?
3. How are parameters passed to the function?
4. What is the use of the return statement in a function?
5. Can we use arrays instead of passing three separate numbers?
6. What are the different ways to declare a function in C?
7. What is the advantage of using functions?
8. How does the program handle equal numbers?
9. What is the time complexity of comparing three numbers?
10. Can we use recursion instead of conditionals to solve this?

Grade / Marks:

Staff Signature:
EXPNO: 6B SWAPPING TWO NUBERS USING PASS BY VALUE
DATE:

Objective:
To develop a C program that uses a user-defined function to find the maximum
among three numbers, helping students understand the concept of functions,
conditional logic, and function calls in C.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• C functions (definition, declaration, and calling)


• Input and output using scanf() / printf()
• Conditional statements (if, else if, else)
• Basic syntax of C language

Theory / Concept Overview:

A function is a block of code that performs a specific task.


This program uses a user-defined function to compare three integers and return the
largest among them.
Control is passed to the function with arguments (three numbers), and the result is
returned back using the return statement.

Problem Statement:

Write a C program that takes three numbers as input from the user and finds the
maximum of the three numbers using a user-defined function.
Algorithm :

Step 1: Start
Step 2: Define a function `maxOfThree(int a, int b, int c)`
Step 3: Inside the function, use if-else conditions to compare a, b, and c
Step 4: Return the largest number
Step 5: In main(), read three numbers from the user
Step 6: Call the function and print the result
Step 7: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Input: 10 25 15
Output: The maximum number is: 25
Test Case 2:
Input: 8 3 8
Output: The maximum number is: 8
Test Case 3:
Input: -5 -10 -2
Output: The maximum number is: -2

Result:

The program successfully determines the largest of three numbers using a function.

Viva Questions:

1. What is a function in C?
2. What is the return type of the function used in this program?
3. How are parameters passed to the function?
4. What is the use of the return statement in a function?
5. Can we use arrays instead of passing three separate numbers?
6. What are the different ways to declare a function in C?
7. What is the advantage of using functions?
8. How does the program handle equal numbers?
9. What is the time complexity of comparing three numbers?
10. Can we use recursion instead of conditionals to solve this?

Grade / Marks:

Staff Signature:
EXPNO: 6C SWAPPING TWO NUMBERS USING PASS BY REFERENCE
DATE:

Objective:

To develop a C program that demonstrates swapping two numbers using pass by reference, helping students
understand the concept of pointers, function calls, and memory referencing in C programming.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Basic C syntax
• Functions in C
• Pointers and address operators (&, *)
• Call by reference vs. call by value

Theory / Concept Overview:

In pass by reference, the actual memory address of variables is passed to a function using pointers. This
allows the function to modify the actual variables in the calling function.
Swapping two numbers using pass by reference means interchanging the values of two variables using a
function that accepts pointer arguments.

Problem Statement:

Write a C program to swap two numbers using pass by reference. The function should accept two pointers as
arguments and swap their values.
Algorithm :

Step 1: Start
Step 2: Define a function swap(int *a, int *b)
Step 3: Inside swap, use a temporary variable to swap the values at the addresses
Step 4: In main(), read two numbers from the user
Step 5: Call the swap() function with the addresses of the two numbers
Step 6: Display the swapped values
Step 7: Stop

Program Logic:
Flowchart:
Sample Input/Output:
Test Case 2:
Input:
Enter two numbers: 5 10
Output:
Before swapping: num1 = 5, num2 = 10
After swapping: num1 = 10, num2 = 5
Test Case 2:
Input:
Enter two numbers: -3 7
Output:
Before swapping: num1 = -3, num2 = 7
After swapping: num1 = 7, num2 = -3

Result:

The program successfully swaps two numbers using pass by reference with pointers.

Viva Questions:

1. What is the difference between pass by value and pass by reference?


2. What are pointers in C?
3. What is the use of the * and & operators?
4. Why do we use a temporary variable in swapping?
5. Can you swap numbers without using a third variable?
6. What happens if you pass variables without using & in this program?
7. What is the output of printf("%d", *a); inside the swap function?
8. What is the scope of the variables used in main()?
9. How is memory allocated for num1 and num2?
10. How would this program change if written using call by value?

Grade / Marks:

Staff Signature:
EXPNO: 7 FACTORIAL OF GIVEN NUMBER USING RECURSIVE FUNCTION
DATE:

Objective:

To develop a C program that calculates the factorial of a given number using recursion, helping students
understand recursive functions and their execution flow.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• C syntax and structure


• Functions and recursion
• Integer data types and return types
• Concept of factorial (n! = n × (n-1) × ... × 1)

Theory / Concept Overview:

Factorial of a non-negative integer n is the product of all positive integers less than or equal to n.
Mathematically:
n! = n × (n-1) × (n-2) × ... × 1
0! = 1 (by definition)
In recursion, a function calls itself with a modified parameter until a base condition is met. This method is
useful for solving problems like factorials, Fibonacci sequences, etc.

Problem Statement:

Write a C program to find the factorial of a given number using a recursive function.
Algorithm :

Step 1: Start
Step 2: Define a recursive function factorial(n)
Step 3: If n == 0 or n == 1, return 1 (base case)
Step 4: Else return n * factorial(n - 1)
Step 5: In main(), read input number from user
Step 6: Call factorial function and display result
Step 7: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
Input:
Enter a non-negative integer: 5
Output:
Factorial of 5 is 120
Test Case 2:
Input:
Enter a non-negative integer: 0
Output:
Factorial of 0 is 1
Test Case 3:
Input:
Enter a non-negative integer: -3
Output:
Factorial is not defined for negative numbers.

Result:

The program correctly calculates the factorial of a given number using a recursive function.

Viva Questions:

1. What is recursion?
2. How does recursion differ from iteration?
3. What is the base case in a recursive function?
4. What is factorial of 0 and why?
5. What happens if you don’t include a base case in recursion?
6. Can recursion lead to stack overflow? Explain.
7. What are the advantages and disadvantages of recursion?
8. Write the factorial of 4 using recursive breakdown.
9. What data type is used to store factorials in C?
10. Can you write the same program using a loop instead of recursion?

Grade / Marks:

Staff Signature:
EXPNO: 8A POINTERS TO FUNCTIONS - CALCULATING AREA OF A TRIANGLE
DATE:

Objective:

To develop a C program to calculate the area of a triangle using pointers to functions, helping students
understand how to use function pointers in C for modular and flexible code design.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Basics of C programming
• Functions and pointers
• Function pointer declaration and usage
• Arithmetic operations
• Formula for area of triangle:
Area=12×base×height\text{Area} = \frac{1}{2} \times \text{base} \times \text{height}Area=21
×base×height

Theory / Concept Overview:

A pointer to a function is a pointer that stores the address of a function that can be called later. It allows
calling different functions dynamically at runtime, which increases code modularity and reusability.
For a triangle, the formula for area is:
Area=12×base×height\text{Area} = \frac{1}{2} \times \text{base} \times \text{height}Area=21
×base×height

Problem Statement:

Write a C program to calculate the area of a triangle using a function and a pointer to that function.
Algorithm :

Step 1: Start
Step 2: Declare a function to calculate the area of a triangle
Step 3: Declare a pointer to the function
Step 4: In main(), take base and height as input
Step 5: Assign function pointer to the area function
Step 6: Call the function through the pointer
Step 7: Display the result
Step 8: Stop

Program Logic:
Flowchart:
Sample Input/Output:
Test Case 1:
Input:
Enter the base of the triangle: 10
Enter the height of the triangle: 5
Output:
Area of the triangle = 25.00
Test Case 2:
Input:
Enter the base of the triangle: 6.5
Enter the height of the triangle: 4
Output:
Area of the triangle = 13.00

Result:

The program successfully calculates the area of a triangle using function pointers, demonstrating how to
apply pointers to functions in C.

Viva Questions:

1. What is a function pointer in C?


2. How do you declare a pointer to a function?
3. Why are function pointers used?
4. What is the syntax to call a function using a function pointer?
5. What are the advantages of using function pointers?
6. What is the formula for the area of a triangle?
7. Can function pointers be used with arrays of functions?
8. What is the return type of the area_of_triangle function in this program?
9. Is memory dynamically allocated in this program?
10. What will happen if you forget to assign the function address to the pointer?

Grade / Marks:

Staff Signature:
EXPNO: 8B POINTERS & ARRAYS FINDING MEAN OF N NUMBERS USING ARRAYS
DATE:

Objective:

To write a C program to calculate the mean (average) of n numbers using arrays and pointers, helping
students understand how pointers interact with arrays and how data can be accessed and processed using
pointer arithmetic.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Basic understanding of arrays in C


• Use of pointers
• Pointer arithmetic
• Loop constructs (for, while)
• Formula for mean:
Mean=Sum of all numbersTotal count\text{Mean} = \frac{\text{Sum of all numbers}}{\text{Total
count}}Mean=Total countSum of all numbers

Theory / Concept Overview:

In C, arrays and pointers are closely related. The name of an array points to the first element. Using a
pointer, we can iterate through the array using pointer arithmetic.
The mean of a list of numbers is calculated by summing up all elements and dividing the sum by the count
of elements.

Problem Statement:

Write a C program to read n numbers into an array, compute the sum using pointers, and then calculate the
mean value.
Algorithm :
Step 1: Start
Step 2: Declare an array and a pointer
Step 3: Read the number of elements (n)
Step 4: Read n numbers into the array
Step 5: Use pointer to traverse and calculate the sum
Step 6: Calculate mean = sum / n
Step 7: Display the mean
Step 8: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1: Test Case 2:


Input: Input:
Enter the number of elements: 5 Enter the number of elements: 3
Enter 5 numbers: Enter 3 numbers:
10 2.5
20 3.5
30 4.0
40 Output:
50 Mean of the entered numbers = 3.33
Output:
Mean of the entered numbers = 30.00

Result:

The program successfully calculates the mean value of n numbers using pointers and arrays in C.

Viva Questions:

1. What is a pointer in C?
2. How are arrays and pointers related?
3. How do you access an array element using a pointer?
4. What is the formula for calculating mean?
5. What is pointer arithmetic?
6. What is the advantage of using pointers over array indexing?
7. Can you explain the meaning of *(ptr + i)?
8. What is the default base address of an array in C?
9. Is ptr = numbers; the same as ptr = &numbers[0];?
10. Can you use dynamic memory allocation in this program? If yes, how?

Grade / Marks:

Staff Signature:
EXPNO: 9A NESTED STRUCTURES: PRINTING EMPLOYEE PERSONAL DETAILS
DATE:

Objective:
To develop a C program that demonstrates how to store and access employee personal details using nested
structures, helping understand structure within structure usage in C programming.
Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Understanding of structures in C
• Use of nested structures
• Input/output in C
• Accessing structure members using dot (.) operator

Theory / Concept Overview:

A structure in C is a user-defined data type that groups related variables of different types.
Nested structures are structures that contain another structure as a member.
This is useful in organizing complex data. For example, an employee's personal details can be grouped in
one structure, and their job details in another.

Problem Statement:

Write a C program that defines and uses a nested structure to store and print the employee's personal and
address details such as:
• Name
• ID
• Age
• Address (Door No, Street, City, Pin Code)
Algorithm :

Step 1. Define an inner structure 'Address' with door no, street, city, pin.
Step 2. Define an outer structure 'Employee' with id, name, age and Address.
Step 3. Read the employee details using scanf.
Step 4. Display the entered data using printf.
Step 5. End.

Program Logic:
Flowchart:
Sample Input/Output:

Test case 1: Test case 1:


Input: Input:
Enter Employee ID: 101 Enter Employee ID: 10
Enter Employee Name: Ramesh Kumar Enter Employee Name: Kumar
Enter Employee Age: 30 Enter Employee Age: 30
Enter Door Number: 12 Enter Door Number: 155
Enter Street Name: Gandhi Street Enter Street Name: old Street
Enter City: Chennai Enter City: Chennai
Enter Pin Code: 600001 Enter Pin Code: 600006
Output: Output:
--- Employee Details --- --- Employee Details ---
ID : 101 ID : 10
Name : Ramesh Kumar Name : Kumar
Age : 30 Age : 50
Address : 12, Gandhi Street, Chennai - 600001 Address : 12, old Street, Chennai - 600006

Result:

The C program successfully accepts and prints employee personal and address details using nested
structures.

Viva Questions:

1. What is a structure in C?
2. What do you mean by a nested structure?
3. How do you access a nested structure member?
4. What is the use of scanf(" %[^\n]", name) in the program?
5. Can a structure contain another structure as a member?
6. What is the difference between structure and array?
7. Can we use typedef with nested structures? Why?
8. Is memory allocated to structure members automatically?
9. Can you pass a structure to a function? How?
10. Can nested structures be multi-level? Explain.

Grade / Marks:

Staff Signature:
EXPNO: 9B POINTERS TO STRUCTURS: PRINTING
STUDENT DETAILS
Objective:
To develop a C program that uses pointers to structures to input and display student details such as marks,
calculate average and print the grade based on the average.
Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:
• Structure declaration and initialization in C
• Using pointers to access structure members (-> operator)
• Basic arithmetic operations
• Conditional statements (if-else)
Theory / Concept Overview:
• Structure: A user-defined data type in C that allows grouping of variables of different types.
• Pointer to Structure: Allows dynamic access and manipulation of structure members.
• The -> operator is used to access structure members using a pointer.

Problem Statement:
Write a C program using pointers to structures to:
• Input a student's name, roll number, and marks in 3 subjects
• Calculate total and average marks
• Print grade based on average using the following grading system:
Average Marks Grade
>= 90 A
80 – 89 B
70 – 79 C
60 – 69 D
< 60 F
Algorithm :

Step 1: Start
Step 2: Define a structure 'Student' with rollNo, name, marks[3], total, average, and grade.
Step 3: Declare a structure variable and a pointer to it.
Step 4: 3. Use pointer to input and calculate values.
Step 5: Compute total and average marks.
Step 6: Assign grade based on average.
Step 7: Display student details using pointer.
Step 8: Stop

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1: Test Case :


Input: Input:
Enter Roll Number: 123 Enter Roll Number: 12
Enter Name: Suresh Kumar Enter Name: Suresh
Enter marks in 3 subjects: Enter marks in 3 subjects:
Subject 1: 85 Subject 1: 58
Subject 2: 92 Subject 2: 90
Subject 3: 78 Subject 3: 87
Output: Output:
--- Student Report --- --- Student Report ---
Roll No : 123 Roll No : 12
Name : Suresh Kumar Name : Suresh
Marks : 85.00, 92.00, 78.00 Marks : 58.00, 90.00, 87.00
Total : 255.00 Total : 235.00
Average : 85.00 Average : 78.00
Grade : B Grade : C

Result:

The program correctly uses pointers to structures to process student data, calculate average marks, and
assign grades accordingly.

Viva Questions:

1. What is a structure in C?
2. How do you declare a pointer to a structure?
3. What is the difference between . and -> operators?
4. How is memory accessed using a structure pointer?
5. Why is structure used in this program?
6. Can a structure have an array as a member?
7. Can we return a structure from a function?
8. What is the size of a structure?
9. Can structures be nested in this program?
10. How would you extend this program to handle multiple students?

Grade / Marks:

Staff Signature:
EXPNO: 9C ARRAY OF STRUCTURES: CALCULATING STUDENT MARK DETAILS

Objective:

To write a C program that uses an array of structures to store and display the details of 5 students, including
their name, roll number, marks in 3 subjects, total marks, and average.
Pre-requisite Knowledge:
• Basics of C programming
• Use of structures in C
• Use of arrays
• Loops and basic input/output
Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Basics of C programming
• Use of structures in C
• Use of arrays
• Loops and basic input/output

Theory / Concept Overview:

• A structure in C allows grouping related variables of different types under a single name.
• An array of structures helps store multiple records (like student data).
• We can access individual structure members using . operator or loops.

Problem Statement:
Write a program to:
• Input the name, roll number, and marks in 3 subjects for 5 students
• Calculate total and average marks for each student
• Display all the collected and calculated details.
Algorithm :

Step 1:Start
Step 2:Define a structure Student with roll number, name, marks[3], total, and average.
Step 3:Declare an array of 5 structures.
Step 4:Use a loop to read input for each student.
Step 5:Inside the loop, calculate total and average marks.
Step 6:Use another loop to display the details of all students.
Step 7:Stop

Program Logic:
Flowchart:
Sample Input/Output:
Test Case 1: Test Case 2:
Input: Input:
Enter details for Student 1 Enter details for Student 2
Enter Roll Number: 101 Enter Roll Number: 102
Enter Name: Ravi Enter Name: Rani
Enter marks for subject 1: 85 Enter marks for subject 1: 85
Enter marks for subject 2: 90 Enter marks for subject 2: 90
Enter marks for subject 3: 80 Enter marks for subject 3: 80
... ...
(Repeat for 5 students) (Repeat for 5 students)
Output: Output:
--- Student Mark List --- --- Student Mark List ---
RollNo Name Marks Total Average RollNo Name Marks Total Average
101 Ravi 85.0 90.0 80.0 255.0 85.00 101 Ravi 85.0 90.0 80.0 255.0 85.00
102 Priya 78.0 88.0 82.0 248.0 82.67 102 Priya 78.0 88.0 82.0 248.0 82.67
... ...

Result:

The program successfully uses an array of structures to manage and process mark details of multiple
students.

Viva Questions:

1. What is a structure in C?
2. How do you declare an array of structures?
3. How is an individual element of a structure accessed?
4. What are the advantages of using structures in this program?
5. Can a structure contain another structure?
6. How do you calculate average using structures?
7. How is memory allocated for an array of structures?
8. What is the use of scanf(" %[^\n]", name)?
9. What is the difference between array and structure?
10. How can you sort students by average marks?

Grade / Marks:

Staff Signature:
EXPNO: 10A READING AND WRITING FILE
DATE :

Objective:

To write a C program to demonstrate reading from and writing to a text file, using standard file I/O operations like
fopen(), fprintf(), fscanf(), fclose().

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Basic syntax of C programming


• Understanding of file operations in C
• Familiarity with pointers and FILE type

Theory / Concept Overview:

File handling in C involves the following steps:


1. Opening a file using fopen()
2. Writing to a file using fprintf() or fputs()
3. Reading from a file using fscanf(), fgets(), or fgetc()
4. Closing the file using fclose()

Problem Statement:

Write a C program to:


• Open a file named data.txt
• Write some user-provided information into the file
• Close the file
• Reopen the file and read back the contents
• Display the read content on the screen
Algorithm:

1. Declare a FILE pointer.


2. Use fopen() with mode "w" to open a file for writing.
3. Use fprintf() to write data into the file.
4. Close the file using fclose().
5. Reopen the file with mode "r" for reading.
6. Use fscanf() or fgets() to read data.
7. Display the data on the screen.
8. Close the file again.

Program Logic:
Flowchart:
Sample Input/Output:

Test case :1 Test case :1


Input: Input:
Enter your name: Rahul Enter your name: Ram
Enter your age: 21 Enter your age: 215
Output: Output:
Data written to file successfully. Data written to file successfully.
Reading data from file: Reading data from file:
Name: Rahul Name: Ram
Age: 21 Age: 215

Result:

The program successfully demonstrates how to perform file write and read operations using C language.

Viva Questions:
1. What is a file in C?
2. What is the difference between text and binary files?
3. What is the use of fopen()?
4. Explain the file modes: "r", "w", "a", "rb", "wb".
5. What does fclose() do?
6. How do you read a line from a file?
7. What is the difference between fscanf() and fgets()?
8. How can you check if a file opened successfully?
9. What happens if you open an existing file with mode "w"?
10. Can FILE * be used without including stdio.h?

Grade / Marks:

Staff Signature:
EXP NO: 10B PROGRAM TO COUNT THE NUMER OF CHARACTERS AND
NUMBER OF LINES IN A FILE USING FILE POINTERS

Objective:

To write a C program that counts the number of characters and lines in a given file using file pointers.
Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Understanding of C syntax
• Concepts of file handling in C
• Familiarity with loops and character I/O

Theory / Concept Overview:

In C, file handling allows you to read and write data to files using the standard I/O library (stdio.h).
• FILE * is used to declare a file pointer.
• fopen() opens a file.
• fgetc() reads a character from a file.
• fclose() closes an opened file.
This program counts:
• Characters using a loop that reads one character at a time.
• Lines by counting each occurrence of \n (newline character).

Problem Statement:

Write a C program to:


• Open an existing text file.
• Read its contents character by character.
• Count and display the number of characters and lines in the file.
Algorithm:

1. Declare a file pointer.


2. Use fopen() in "r" mode to open the file.
3. If the file does not exist, print an error.
4. Initialize charCount = 0, lineCount = 0.
5. Loop through the file using fgetc(fp):
o Increment charCount for every character read.
o Increment lineCount if the character is '\n'.
6. Display the final counts.
7. Close the file.

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1: Test Case 2:


Content of sample.txt: Test Case 1: Content of sample.txt:
Hello World Hello World
This is a file This is a file
With three lines With three lines
Output: Output:
Total characters: 45 Total characters: 45
Total lines: 2 Total lines: 2

Result:

The program successfully counts and displays the number of characters and lines in the file using file
pointers.

Viva Questions:

1. What is a file pointer in C?


2. What does fgetc() do?
3. What does EOF represent?
4. What is the purpose of fclose()?
5. How do you open a file for reading?
6. How can you count the number of lines in a file?
7. How do you check if a file opened successfully?
8. What is the difference between "r" and "w" modes?
9. What happens if you try to open a non-existent file in "r" mode?
10. Can we read files line by line instead of character by character? How?

Grade / Marks:

Staff Signature:
EXP NO: 10C PROGRAM TO COPY ONE FILE TO ANOTHER
DATE:

Objective:

To write a C program that copies the contents of one file into another using file handling concepts in C.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Basics of C programming
• Understanding of file handling: FILE *, fopen(), fgetc(), fputc(), fclose()
• Concept of loops and character I/O in C

Theory / Concept Overview:

In C, file copying involves reading from a source file and writing to a destination file using:
• fgetc() to read one character at a time.
• fputc() to write one character at a time.
The process uses two file pointers:
• One for reading the source file (fopen(filename, "r"))
• One for writing to the destination file (fopen(filename, "w"))

Problem Statement:

Write a C program to:


• Take a source file and a destination file as input.
• Copy all contents from the source file to the destination file.
• Display a success message upon completion.
Algorithm :

1. Declare two file pointers: fsource, fdest.


2. Open the source file in "r" mode.
3. Open the destination file in "w" mode.
4. If either file fails to open, print an error and exit.
5. Loop to read character by character using fgetc().
6. Write each character to the destination file using fputc().
7. Close both files using fclose().
8. Display success message.

Program Logic:
Flowchart:
Sample Input/Output:

Test Case :1 Test Case :2


Content of source.txt: Content of source.txt:
Welcome to C Programming. Welcome to C Programming.
File Handling is powerful! File Handling is powerful!
Output after execution: Output after execution:
File copied successfully! File copied successfully!
Content of destination.txt: Content of destination.txt:
Welcome to C Programming. Welcome to C Programming.
File Handling is powerful! File Handling is powerful!

Result:

The program successfully copies the entire content of one file (source.txt) into another file (destination.txt)
using file handling in C.

Viva Questions:

1. What are file pointers in C?


2. What is the use of fopen() function?
3. What modes are used in fopen()?
4. What does fgetc() do?
5. What is the difference between fputc() and fprintf()?
6. What is EOF and how is it used?
7. What will happen if the destination file already exists?
8. How do you handle file not found errors?
9. Can you copy binary files using the same logic?
10. What is the significance of closing files after use?

Grade / Marks:

Staff Signature:
EXP NO: 10D PROGRAM TO COMPUTE AREA OF CIRCLE USING
PREPROCESSOR DIRECTIVES
DATE:

Objective:

To write a C program that computes the area of a circle using a macro definition for the constant value of π
(pi), leveraging preprocessor directives like #define.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Basics of C programming
• Use of macros and preprocessor directives like #define
• Formula for area of a circle:
Area=π×r2\text{Area} = \pi \times r^2Area=π×r2

Theory / Concept Overview:

• The preprocessor directive #define is used to define constants before the compilation begins.
• The area of a circle is calculated using the formula:
Area=π×radius2\text{Area} = \pi \times \text{radius}^2Area=π×radius2
• Here, instead of hardcoding the value of π (3.14), we define it using:
#define PI 3.14159

Problem Statement:
Write a program in C to:
• Accept the radius of a circle as input.
• Use a macro to define the value of π.
• Compute and display the area of the circle.

Algorithm :
1. Define PI using #define PI 3.14159
2. Read the value of radius from the user.
3. Use the formula Area = PI * radius * radius.
4. Print the result.

Program Logic:
Flowchart:
Sample Input/Output:
Test Case 1:
Input:
Enter the radius of the circle: 5
Output:
Area of the circle = 78.54
Test Case 2:
Input:
Enter the radius of the circle: 2.5
Output:
Area of the circle = 19.63
Test Case 3:
Input:
Enter the radius of the circle: 10
Output:
Area of the circle = 314.16

Result:
The program correctly calculates the area of a circle using a preprocessor directive (#define) for π.

Viva Questions:
1. What is a preprocessor directive in C?
2. What is the use of #define in this program?
3. Why use a macro instead of a variable for π?
4. What is the formula used to find the area of a circle?
5. What is the output if the radius entered is zero?
6. Can we change the value of PI at runtime?
7. What is the difference between #define and const?
8. Is #define a runtime or compile-time feature?
9. What happens if you use PI without defining it?
10. Can #define be used to define functions?

Grade / Marks:

Staff Signature:
EXP NO: 10E PROGRAM TO COMPUTE ADDITION OF TWO NUMBERS USING
COMMAND LINE ARGUMENTS
DATE :

Objective:
To develop a C program that accepts two integers through command line arguments and computes their
sum.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Basics of C programming
• Command-line execution of programs
• Using argc and argv[] in main()
• Type casting strings to integers (atoi())

Theory / Concept Overview:

Command line arguments allow the user to pass values to a program during its execution through the
terminal. These arguments are accessible via argc (argument count) and argv[] (argument vector - array
of strings).
Example:
bash
./program 10 20
Here, argv[1] = "10" and argv[2] = "20", which are then converted to integers using atoi().

Problem Statement:

Write a C program that:


• Accepts two integers as command line arguments.
• Computes and displays their sum.
Algorithm :

1. Start the program with main(int argc, char *argv[])


2. Check if argc == 3 (1 for program name + 2 numbers)
3. Convert argv[1] and argv[2] to integers using atoi()
4. Add the two integers.
5. Print the result.

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1:
➤ Command:
./add 15 25
➤ Output:
Sum of 15 and 25 is: 40
➤ Command (with wrong usage):
./add 10
Test Case 2:
➤ Command:
./add 150 250
➤ Output:
Sum of 150 and 250 is: 400
➤ Command (with wrong usage):
./add 10
➤ Output:

Result:
The program successfully computes the sum of two numbers passed via command line arguments.

Viva Questions:

1. What are command line arguments in C?


2. What is the role of argc and argv[]?
3. How can you convert a string to an integer in C?
4. What will happen if fewer than two arguments are passed?
5. How do you compile and run a program with command line arguments in C?

Grade / Marks:

Staff Signature:
EXP NO: 11A SINGLY LIKNED LIST IMPLEMENTATION
DATE:

Objective:
To understand and implement basic operations (insertion, deletion, traversal) in a Singly Linked List using
C programming.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:
• Basics of structures in C
• Dynamic memory allocation using malloc()
• Pointers and pointer manipulation
• Function usage and recursion in C (optional)

Theory / Concept Overview:


A Singly Linked List is a linear data structure where each element (node) contains:
1. Data
2. Pointer to the next node
The last node points to NULL indicating the end of the list.
Operations in a singly linked list include:
• Insertion (at beginning, end, or specific position)
• Deletion (by value or position)
• Traversal (displaying elements)

Problem Statement:

Write a C program to perform the following operations on a singly linked list:


• Insert a node at the end
• Delete a node by value
• Display all elements
Algorithm :

1. Define a struct Node with data and next pointer.


2. Initialize head as NULL.
3. For insertion:
o Allocate memory for new node
o Set data and link it at the correct position
4. For deletion:
o Traverse to find the node
o Adjust links and free memory
5. For traversal:
o Loop through the list and print data

Program Logic:
Flowchart:
Sample Input/Output:

Test Case :1 Test Case :1


1. Insert 1. Insert
2. Delete 2. Delete
3. Display 3. Display
4. Exit 4. Exit
Enter choice: 1 Enter choice: 1
Enter value to insert: 10 Enter value to insert: 10
Enter choice: 1 Enter choice: 1
Enter value to insert: 20 Enter value to insert: 20
Enter choice: 3 Enter choice: 3
List: 10 -> 20 -> NULL List: 10 -> 20 -> NULL
Enter choice: 2 Enter choice: 2
Enter value to delete: 10 Enter value to delete: 10
Enter choice: 3 Enter choice: 3
List: 20 -> NULL List: 20 -> NULL

Result:

The program successfully performs insert, delete, and display operations on a singly linked list.

Viva Questions:

1. What is a linked list?


2. How is a linked list different from an array?
3. What are the advantages of linked lists?
4. What happens when you insert at the beginning of a list?
5. What does malloc() do in C?
6. How do you detect a loop in a linked list?
7. What are the types of linked lists?

Grade / Marks:

Staff Signature:
EXP NO: 11B STACK IMPLEMENTATION
DATE:

Objective:
To implement Stack operations (push, pop, display) using arrays in C and understand the Last-In-First-Out
(LIFO) principle.
Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:
• Arrays and functions in C
• Concepts of stack (LIFO)
• Conditional statements and loops
• Function calls and stack-based memory

Theory / Concept Overview:


A Stack is a linear data structure that follows the Last-In, First-Out (LIFO) principle.
• The element added last is removed first.
• Two main operations:
o push() — to insert an element
o pop() — to remove the top element
Additional operation:
• display() — to show the current elements of the stack
Stack is widely used in:
• Expression evaluation
• Recursion handling
• Undo features in applications

Problem Statement:

Write a C program to perform basic stack operations using an array:


• Push an element
• Pop an element
• Display the stack
Algorithm :
1. Define a stack[] with a maximum size and a variable top = -1.
2. For push:
o Check if top == MAX - 1 (stack overflow)
o Else increment top and assign value to stack[top]
3. For pop:
o Check if top == -1 (stack underflow)
o Else return stack[top] and decrement top
4. For display:
o Print all elements from top to 0

Program Logic:
Flowchart:
Sample Input/Output:
Test Case 1: Test Case 2:
1. Push 1. Push
2. Pop 2. Pop
3. Display 3. Display
4. Exit 4. Exit
Enter your choice: 1 Enter your choice: 1
Enter value to push: 10 Enter value to push: 10
10 pushed to stack. 10 pushed to stack.
Enter your choice: 1 Enter your choice: 1
Enter value to push: 20 Enter value to push: 20
20 pushed to stack. 20 pushed to stack.
Enter your choice: 3 Enter your choice: 3
Stack elements: 20 10 Stack elements: 20 10
Enter your choice: 2 Enter your choice: 2
20 popped from stack. 20 popped from stack.
Enter your choice: 3 Enter your choice: 3
Stack elements: 10 Stack elements: 10

Result:
The C program successfully demonstrates stack operations using an array: push, pop, and display.

Viva Questions:

1. What is a stack?
2. What does LIFO mean?
3. What is stack overflow and underflow?
4. Can stack be implemented using a linked list?
5. What is the difference between stack and queue?
6. Where are stacks used in real life?
7. How would you reverse a string using a stack?
8. What is the time complexity of push and pop?

Grade / Marks:

Staff Signature:
EXP NO: 11C QUEUE IMPLEMENTATION
DATE:

Objective:

To implement Queue operations (enqueue, dequeue, display) using arrays in C, and understand the First-In-
First-Out (FIFO) principle.

Software/Hardware Requirements:

Hardware Minimum Requirement


Processor (CPU) Intel Pentium IV or equivalent
RAM 512 MB
Storage 100 MB free disk space
Display 800 × 600 resolution
Input Devices Keyboard, Mouse

Software Recommended Requirement


Operating System Windows (7/8/10/11), Linux (Ubuntu, Fedora), or macOS
C Compiler GCC (GNU Compiler Collection), Turbo C, Clang, or Visual C++
IDE/Text Editor Code::Blocks, Dev-C++, Turbo C++, VS Code, Eclipse, or any text editor
Interpreter/Terminal Command Prompt (Windows) or Terminal (Linux/macOS)
C Standard Library Available by default with most compilers

Pre-requisite Knowledge:

• Basic understanding of arrays and functions in C


• Control structures (if, switch, loops)
• Concepts of memory organization and data structures

Theory / Concept Overview:

A Queue is a linear data structure that works on the FIFO (First-In-First-Out) principle.
• The element added first is removed first.
• Basic operations:
o enqueue() – insert element at the rear
o dequeue() – remove element from the front
o display() – show current queue contents
Applications of queue:
• Job scheduling
• CPU task management
• Printing tasks in printers

Problem Statement:
Write a C program to implement a queue using array and perform basic operations like enqueue, dequeue,
and display.
Algorithm :
1. Initialize: front = -1, rear = -1, define queue[MAX]
2. Enqueue:
o Check for overflow: rear == MAX - 1
o If queue is empty: front = 0
o Increment rear, insert value at queue[rear]
3. Dequeue:
o Check for underflow: front == -1 || front > rear
o Remove element at queue[front]
o Increment front
4. Display:
o Traverse from front to rear

Program Logic:
Flowchart:
Sample Input/Output:

Test Case 1: Test Case 2:


1. Enqueue 1. Enqueue
2. Dequeue 2. Dequeue
3. Display 3. Display
4. Exit 4. Exit
Enter your choice: 1 Enter your choice: 1
Enter value to enqueue: 10 Enter value to enqueue: 10
10 enqueued to the queue. 10 enqueued to the queue.
Enter your choice: 1 Enter your choice: 1
Enter value to enqueue: 20 Enter value to enqueue: 20
20 enqueued to the queue. 20 enqueued to the queue.
Enter your choice: 3 Enter your choice: 3
Queue elements: 10 20 Queue elements: 10 20
Enter your choice: 2 Enter your choice: 2
10 dequeued from the queue. 10 dequeued from the queue.
Enter your choice: 3 Enter your choice: 3
Queue elements: 20 Queue elements: 20

Result:

The C program successfully implements queue operations using arrays and performs enqueue, dequeue, and
display.

Viva Questions:
1. What is a queue?
2. What is FIFO in data structures?
3. What is the difference between queue and stack?
4. What are the types of queues?
5. What is a circular queue?
6. What is the maximum size of this queue?
7. What is queue overflow and underflow?
8. Where are queues used in real life?
9. Can a queue be implemented using linked list?
10. What is the time complexity of enqueue and dequeue?

Grade / Marks:

Staff Signature:

You might also like