Assignment Title: Arrays in C - Fundamentals and
Applications
Course: Data Structures
Objective: To understand the fundamental operations of arrays in C and apply them to solve
real-world problems.
Practice Questions (revision):
Part A: Fundamentals of Arrays
1. Array Basics
Write a C program to:
o Declare and initialize an array of integers of size 10.
o Accept input from the user to populate the array.
o Display the array elements using a loop.
2. Maximum and Minimum
Write a function that takes an array as input and returns the maximum and minimum
elements of the array. Demonstrate this with a program.
3. Array Reversal
Write a program to reverse the elements of an array in-place (without using an
additional array). Display the reversed array.
Part B: Advanced Operations
4. Linear Search
Implement a linear search algorithm in C. Write a program that:
o Accepts a number from the user to search in the array.
o Displays the index of the element if found or a message if not found.
5. Insertion and Deletion
Write a program to perform the following operations on an array of size 20:
o Insert a new element at a specified position.
o Delete an element at a specified position.
o Display the array after each operation.
6. Sorting
Write a program to sort an array using the Bubble Sort algorithm. Display the array
before and after sorting.
Marks: 10 Marks
Instructions:
Submit the assignment in both soft and hard copies. (Hard copy in a separate
assignment copy)
Use proper indentation and comments in your code.
Demonstrate the output with test cases for each program.
Deadline: 15th January 2025
Part C: Assignment 1: Applications of Arrays
1. Matrix Representation and Operations
Write a program to:
o Take input for a 3x3 matrix.
o Display the matrix in proper format.
o Compute and display the transpose of the matrix.
2. Merging and Intersecting Arrays
Write a program to:
o Merge two arrays into a single array without duplicates.
o Find the intersection of two arrays.
Test the program with arrays of size 5 each.
3. Stock Price Analysis
Given an array where each element represents the price of a stock on a given day,
write a program to calculate:
o The maximum profit that can be earned by buying and selling on different days.
o If no profit is possible, display a message accordingly.
Example Input:
Stock Prices: 7, 1, 5, 3, 6, 4
Example Output:
Maximum Profit: 5
Buy on Day 2 at price 1 and sell on Day 5 at price 6
4. Write a program to find two numbers in an array that add up to a target sum.
o Print the indices of the two numbers if a solution exists.
o If no solution exists, display a suitable message.
Example Input:
Array: 2, 7, 11, 15
Target Sum: 9
Example Output: Indices:
0, 1 (2 + 7 = 9)
5. Dynamic Array Implementation (Optional/Bonus)
Write a program to dynamically allocate memory for an array using malloc() and
free().
o Allow the user to specify the size of the array at runtime.
o Perform basic operations such as insertion, deletion, and displaying elements.
Submission Checklist:
1. Source code for each program.
2. Screenshots or terminal output showing the results for at least two test cases for each
program. Note: Each program must be named and save as entrynumber_prgno.c
3. A brief report explaining the logic behind each program (optional).
Grading Criteria:
Task Marks
Correctness of Output 40%
Code Readability and Comments 20%
Test Case Coverage 20%
Submission on Time 10%
Bonus Task (Dynamic Arrays) 10%
Learning Outcomes:
Develop a strong foundation in array manipulation and operations.
Gain practical experience in implementing search, sort, and matrix operations.
Understand memory management concepts for dynamic arrays.