Biotech Wb
Biotech Wb
(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:
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
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:
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:
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:
    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:
Pre-requisite Knowledge:
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:
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:
Pre-requisite Knowledge:
Basic structure of C program
Variables and Data Types
Input and Output Functions
Arithmetic Operations
Concept of Memory Storage
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:
Result:
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:
Pre-requisite Knowledge:
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:
Pre-requisite Knowledge:
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:
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:
Pre-requisite Knowledge:
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:
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:
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
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:
Pre-requisite Knowledge:
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:
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:
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)
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
   Pre-requisite Knowledge:
   •   Basics of C programming
   •   Use of for loop
   •   Understanding variables and data types
   •   Concept of sequence generation
   •   Fibonacci series logic
   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:
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
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:
Pre-requisite Knowledge:
•   Basics of C programming
•   Loops (while or for)
•   Arithmetic operators (%, /, *)
•   Understanding of number systems
•   Functions and variables
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:
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:
Pre-requisite Knowledge:
   •   Variables and Data Types in C
   •   Loops (for, while)
   •   Conditional statements (if, else)
   •   Modulus operator %
   •   Prime number concept from mathematics
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:
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)
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:
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
Pre-requisite Knowledge:
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:
Viva Questions:
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:
Pre-requisite Knowledge:
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:
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:
Pre-requisite Knowledge:
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:
Result:
The program successfully multiplies two matrices and displays the result if the dimensions are compatible.
Viva Questions:
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:
Pre-requisite Knowledge:
   •   Basic C syntax
   •   Arrays and loops
   •   Conditional statements (if, else)
   •   Input and output functions (scanf(), printf())
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
Pre-requisite Knowledge:
Problem Statement:
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:
  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
Pre-requisite Knowledge:
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:
Software/Hardware Requirements:
Pre-requisite Knowledge:
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:
Pre-requisite Knowledge:
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:
Pre-requisite Knowledge:
   •   Basic C syntax
   •   Functions in C
   •   Pointers and address operators (&, *)
   •   Call by reference vs. call by value
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:
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:
Pre-requisite Knowledge:
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:
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
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:
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:
Pre-requisite Knowledge:
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:
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:
Pre-requisite Knowledge:
   •   Understanding of structures in C
   •   Use of nested structures
   •   Input/output in C
   •   Accessing structure members using dot (.) operator
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:
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:
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:
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:
Pre-requisite Knowledge:
   •   Basics of C programming
   •   Use of structures in C
   •   Use of arrays
   •   Loops and basic input/output
   •   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:
Pre-requisite Knowledge:
Problem Statement:
Program Logic:
Flowchart:
Sample Input/Output:
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:
Pre-requisite Knowledge:
   •   Understanding of C syntax
   •   Concepts of file handling in C
   •   Familiarity with loops and character I/O
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:
Program Logic:
Flowchart:
Sample Input/Output:
Result:
The program successfully counts and displays the number of characters and lines in the file using file
pointers.
Viva Questions:
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:
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
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:
Program Logic:
Flowchart:
Sample Input/Output:
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:
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:
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
•  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:
Pre-requisite Knowledge:
•   Basics of C programming
•   Command-line execution of programs
•   Using argc and argv[] in main()
•   Type casting strings to integers (atoi())
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:
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:
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:
Pre-requisite Knowledge:
   •   Basics of structures in C
   •   Dynamic memory allocation using malloc()
   •   Pointers and pointer manipulation
   •   Function usage and recursion in C (optional)
Problem Statement:
Program Logic:
Flowchart:
Sample Input/Output:
Result:
The program successfully performs insert, delete, and display operations on a singly linked list.
Viva Questions:
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:
Pre-requisite Knowledge:
   •   Arrays and functions in C
   •   Concepts of stack (LIFO)
   •   Conditional statements and loops
   •   Function calls and stack-based memory
Problem Statement:
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:
Pre-requisite Knowledge:
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:
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: