CS 1101- C Lab ( G5 - G8 )
Assignment 6, Marks: 20, Time: 2.00 hours
Date: 10/10/2025
General Instructions:
- Proper indentation and formatting of code is mandatory.
- All programs must be compiled and tested on Linux.
- Add comments wherever necessary to make the code clear and easy to understand.
- Marks will be awarded based on the accuracy and quality of outputs.
- Any instance of plagiarism or unfair means will lead to deduction of marks.
- Inputs should always be taken from the user. If any assumptions are required, state them clearly
in comments.
- After 2 hours, no one should write any code. If found, negative marking will be given.
Submission Guidelines:
- Save your source code files with proper names, e.g. A6_Q1.c, A6_Q2.c, A6_PP1.c.
- Compress all files into a single ZIP folder named: A6_RollNumber.zip.
- Upload the ZIP file using the submission link: [Link]
Q1:
Write a C program to manage books in a library using a structure.
Each book has:
title (string)
author (string)
price (float)
Your program should:
1. Take n as input (number of books).
2. Implement the following functions:
- void inputBooks(struct Book books[], int n): to read details of all books.
- void displayBooks(struct Book books[], int n): to display details of all books.
- struct Book findCostliestBook(struct Book books[], int n): to find and return the book with the
highest price.
3. In the main function, call these functions appropriately.
4. Display the details of the costliest book.
Test Case:
Input:
3
C_Programming Dennis_Ritchie 450.50
Data_Structures Reema_Thareja 520.00
Operating_Systems Galvin 499.99
Output:
Costliest Book: Data_Structures
Author: Reema_Thareja
Price: 520.00
Q2:
Write a C program that:
Reads two matrices A and B from the user (with interactive prompt lines).
If possible, computes the product matrix C = A × B, prints the product matrix.
If not possible, prints "Matrix multiplication not possible with proper reason."
Testcase 1:
Input:
Enter rows and columns of first matrix:
23
Enter rows and columns of second matrix:
32
Enter elements of first matrix:
123
456
Enter elements of second matrix:
78
9 10
11 12
Expected Output:
Product of the two matrices is:
58 64
139 154
Testcase 2 — Invalid multiplication (2×2 × 3×2):
Input:
Enter rows and columns of first matrix:
22
Enter rows and columns of second matrix:
32
Enter elements of first matrix:
12
34
Enter elements of second matrix:
56
78
9 10
Expected Output:
Matrix multiplication is not possible.
—------------------------------------------------------
Practice Problems:
Q1:
Create a structure Book with fields:
id (integer)
title (string)
author (string)
price (float)
Write a program in C with a function to add and display details of n books.
Input:
Enter number of books: 2
Enter details of book 1:
ID: 101
Title: C_Programming
Author: Dennis
Price: 350
Enter details of book 2:
ID: 102
Title: DBMS
Author: Navathe
Price: 250
Output:
Book Details Entered:
ID: 101
Title: C_Programming
Author: Dennis
Price: 350.00
ID: 102
Title: DBMS
Author: Navathe
Price: 250.00
Q2:
Write a C program to check whether a given matrix is symmetric or not.
Use a 2D array to store the matrix.
Write functions to:
1. Input the matrix.
2. Display the matrix.
3. Check whether the matrix is symmetric.
Use conditional statements to print "Matrix is Symmetric" or "Matrix is Not Symmetric".
Test Case 1:
Input:
Enter number of rows and columns: 3 3
Enter elements of the matrix:
123
256
369
Output:
Matrix is:
123
256
369
Matrix is Symmetric
Test Case 2:
Input:
Enter number of rows and columns: 2 2
Enter elements of the matrix:
10
21
Output:
Matrix is:
10
21
Matrix is Not Symmetric
Q3:
Write a C program to manage basic student records for a college.
Each student has the following information:
i. Roll Number (integer)
ii. Name (string)
iii. Marks in 3 subjects (float)
iv. Average Marks (float)
v. Grade (char)
The program should:
1. Allow the user to enter details of n students.
2. Use functions to:
- Input student data
- Calculate average marks and grade
- Display all student records
- Display students who scored above a certain average (use conditional check)
3. Use loops to input and display multiple students.
4. Use conditional statements to assign grades:
- A if average ≥ 85
- B if 70 ≤ average < 85
- C if 50 ≤ average < 70
- D otherwise.
Sample Input (Test Case):
Enter number of students: 2
Enter details for student 1:
Roll No: 101
Name: Ram
Marks in 3 subjects: 90 85 88
Enter details for student 2:
Roll No: 102
Name: Shyam
Marks in 3 subjects: 75 70 72
Sample Output:
All Student Records:
Roll No: 101
Name: Ram
Average: 87.67
Grade: A
Roll No: 102
Name: Shyam
Average: 72.33
Grade: B
Q4:
Write a C program to simulate a simple Cinema Seat Reservation System using a 2D Array.
The cinema hall has seats arranged in rows and columns.
Each seat can have one of the following states:
0 → Seat is available
1 → Seat is booked
The program should allow the user to:
1. Display the current seating arrangement.
2. Book a seat by entering the row and column number.
3. Update and display the seating arrangement after each booking.
4. If a seat is already booked, display an appropriate message.
5. Continue booking until the user chooses to stop.
Test Case:
Input:
Enter number of rows: 3
Enter number of columns: 3
Current Seating:
000
000
000
Menu:
1. Book a seat
2. Exit
Enter your choice: 1
Enter row and column to book seat: 2 3
Seat booked successfully!
Updated Seating:
000
001
000
Q5:
Write a C program that finds the largest element in a 2D array (a matrix).
The logic for finding the maximum element must be implemented inside a separate function.
Test Case 1: Standard Positive Numbers
Input Array:
{
{3, 12, 5, 40},
{15, 2, 88, 7},
{9, 21, 6, 1}
}
Expected Output:
The maximum element in the array is: 88
Test Case 2: All Negative Numbers
Input Array:
{
{-5, -10, -3},
{-2, -8, -1},
{-15, -20, -4}
}
Expected Output:
The maximum element in the array is: -1
Test Case 3: All Elements are the Same
Input Array:
{
{7, 7, 7},
{7, 7, 7}
}
Expected Output:
The maximum element in the array is: 7