0% found this document useful (0 votes)
7 views7 pages

C Lab Manual: Data Structures Exercises

This lab manual for the Data Structures course at Jagannath University outlines various exercises aimed at teaching students fundamental concepts of arrays using C programming. Students will learn to manipulate 1D and 2D arrays through tasks such as finding maximum/minimum values, deleting and inserting elements, sorting, and performing matrix operations. The manual includes sample inputs and outputs for each exercise to guide students in their programming tasks.

Uploaded by

Sanjida Islàm
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)
7 views7 pages

C Lab Manual: Data Structures Exercises

This lab manual for the Data Structures course at Jagannath University outlines various exercises aimed at teaching students fundamental concepts of arrays using C programming. Students will learn to manipulate 1D and 2D arrays through tasks such as finding maximum/minimum values, deleting and inserting elements, sorting, and performing matrix operations. The manual includes sample inputs and outputs for each exercise to guide students in their programming tasks.

Uploaded by

Sanjida Islàm
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

Jagannath University

Department of Computer Science & Engineering


______________________________________________________________________
Lab Manual : 01
Course Code : CSE2207
Course Title : Data Structures
Instructor : Dr. Md. Manowarul Islam, Adjunct Faculty,Department of CSE

Objective:
The objective of this lab is to provide a fundamental idea of array using C programming.
At the end of the lab, students are able to know:
• How to take input into a 1D array.
• How to insert and delete data from a linear array.
• How to sort and reverse a 1D array.
• Understand how to take input into a 2D array and print it.
• Utilize 2D arrays for matrix manipulation and operations.

Lab Tasks

Exercise 1

Write a program to find second maximum and minimum number of an integer array. Show
the sample input and output clearly.

Sample Input Sample Output


17, 4,5,6,2,10 Second Maximum: 10
Second Minimum: 4

Exercise 2

The following algorithm will print the duplicate entry in an integer array.

Write a program in C to find the duplicate number.

ALGORITHM:

• STEP 1: START
• STEP 2: INITIALIZE arr[]= {1, 2, 3, 4, 2, 7, 8, 8, 3}.
• STEP 3: length = sizeof(arr)/sizeof(arr[0])
• STEP 4: PRINT "Duplicate elements in given array:"
• STEP 5: SET i=0. REPEAT STEP 6 to STEP 9 UNTIL i<length
• STEP 6: SET j=i+1. REPEAT STEP 7 and STEP 8 UNTIL i<length
• STEP 7: if(arr[i] == arr[j])
PRINT arr[j]
• STEP 8: j=j+1
• STEP 9: i+1.
• STEP 10: RETURN 0.
• STEP 11: END

Sample Input Sample Output


1, 2, 3, 4, 2, 7, 8, 8, 3 Duplicate elements in given array:

238

3. Write a program in C to delete an element at desired position from an array.

Sample Input Sample Output


Input array elements: 10 20 30 40 50 Array elements: 10, 30, 40, 50
Input position to delete: 2

4. Write a program in C to insert element in array at specified position.

Sample Input Sample Output


Input array elements: 10, 20, 30, 40, Elements of array are: 10, 20, 25, 30,
50 40, 50
Input element to insert: 25

Input position where to insert: 3

5. Find the elements of an array that are greater than a specific Threshold. Create a new
array to store all the elements from the original array that exceed a given threshold.

Sample Input Sample Output


Input array elements: 10,25,89,50,100 89,50,100
Threshold: 30

6. Remove duplicate elements from the 1D array and print the modified array.

Sample Input Sample Output


Input array elements: 10,20,10,30 10,20,30

7. Generate and print the first N elements of the Fibonacci series in a 1D array with initial
conditions: array [0] =0, array[1]=1.

Sample Input Sample Output


N=8. 0,1,1,2,3,5,8,13.

8. Find if an array contains a subarray (Suppose the Subarray length is 2) with a specific
pattern. The subarray pattern is defined as a sequence of two consecutive elements.

Sample Input Sample Output


Input array elements: 1,2,5,7,9,10 Found
Subarray: 5,7
Input array elements: 1,2,3,4,5 Not Found
Subarray: 1,4

9. Write a program in C to modify array elements by adding 3 to elements at odd indexes


and 2 to elements at even indexes.

Sample Input Sample Output


Input array elements: 10, 20, 30,40, 50 Elements of array are: 13,22,33,42,53

10. Write a program in C to find the majority element in a given 1D array. A majority
element is an element that appears more than N/2 times, where N is the size of the array.
If no such element exists, print "No Majority Element Found".
Sample Input Sample Output
Input array elements: 3, 3, 4, 2, 4, 4, 2, 4, 4 Majority Element: 4

11. Write a program in C to find the largest difference (max - min) between any two
elements.
Sample Input Sample Output
Input array elements: 1, 9, 3, 10 Largest difference is 1

12. Write a program in C that moves all zeros in an array to the end while maintaining the
order of non-zero elements.

Sample Input Sample Output


Input array elements: 0, 1, 0, 3, 12 Array after shifting: 1, 3, 12, 0, 0

13. Write a program in C to remove all occurrences of a specific element from the array.

Sample Input Sample Output


Input array elements: 1, 2, 3, 2, 4, 2 Modified array: 1 3 4
Element to remove: 2

14. Write a program in C to rearrange the elements so that the first element is the largest,
the second is the smallest, the third is the second-largest, the fourth is the second-smallest,
and so on — alternating between the next largest and the next smallest values. This
rearrangement creates a "zig-zag" pattern with high and low values alternating.

Sample Input Sample Output


Input array elements: 1, 2, 3, 4, 5, 6 Modified array: 6 1 5 2 4 3

15. Write a program in C to find all leaders of an array. A leader is an element that is strictly
greater than all the elements to its right. Note that the last element is always considered a
leader by definition.

Sample Input Sample Output


Input array elements: 16, 17, 4, 3, 5, 2 Leaders : 17 5 2
16. Write a program in C to Print all unique pairs of elements whose sum equals a given
element.

Sample Input Sample Output


Input array elements: 1, 5, 7, -1, 5 Pairs : (1,5) (7,-1)
Element : 6

17. Write a program in C to find whether a matrix is symmetric or not.

Sample Input Sample Output


Input array elements: The Matrix is Symmetric.

18. Write a program in C to find the product of non-Diagonal elements of a matrix.

Sample Input Sample Output


Input array elements: The product of non-diagonal
elements is: 8064

19. Write a program in C to find the transpose of a square matrix.

Sample Input Sample Output


Input array elements:
20. Write a program in C to perform matrix addition of two matrices of size n x n. Ensure
that the program takes input for both matrices and displays the resulting matrix after
addition.

Sample Input Sample Output


st
Elements of 1 array : Resulting array after addition:

Elements of 2nd array:

21. Write a program in C that takes a 2D array as user input and finds the column with the
maximum sum (i.e., identify the column whose sum of elements is the highest among
all columns in the array).

Sample Input Sample Output

3 No. column has the maximum sum


which is 18

You might also like