Practice Problems On Array
Practice Problems On Array
3. Write a C program to find the maximum and minimum elements, along with their
indices, in an array.
The program should take an array and return both the maximum and minimum
elements along with their indices in the array.
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 2 of 24
5. Write a C program to find the first and last indices of a given integer in an array. If
the integer is not found, return -1.
The program should take an integer array and an integer value as input and output
the first and last index of that integer in the array.
7. Write a C program that removes all occurrences of a given integer from an array
and shifts the remaining elements to the left, placing -1 at the end.
This program should take an array and an integer, remove all occurrences of the
integer from the array, and shift the remaining elements, placing -1 at the end.
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 3 of 24
9. Write a C program that takes two arrays of integers, and stores the sum of
corresponding elements in a third array.
The program should take two arrays of integers and return a new array containing
the sum of corresponding elements.
12.Write a function that takes an array as input, sorts the array from index x to y.
Description:
This problem requires sorting only a specific part of the array, from index x to index
y. The rest of the array should remain unchanged. Sorting a portion of the array
helps in understanding range-based operations on arrays.
Sample Output
Sample Input
7 4 7 1 3 8 10 9
4 7 10 3 8 1 9
2 5
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 4 of 24
7 9235687
9253687
1 4
7 1984567
1984756
3 6
13.Take an array of integers. Output the array of distinct elements and print it’s
length.
Sample Output
Sample Input
8 12463
1211463326 5
5 12
11121 2
3 123
123 3
14. Write a C program to check if there is a pair in an array that sums up to a given
value.
The program should check if there are any two elements in the array that add up to
a given sum.
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 5 of 24
15. Write a C program to find the union (set operation) of two arrays.
The program should take two arrays and return a new array containing all unique
elements from both arrays.
Sample Input Sample Output
3 4 5 7 10
4 7 10
3
10 5 4
16. Write a C program to find the intersection (set operation) of two arrays.
The program should return the common elements between two arrays.
The first line of each input contains the number of elements in the array, then there will
be n integers in the second line. For each input, you have to compute and print the
following statistical parameters:
Mode: The most frequently occurring number in the array. For multiple modes, mention
all.
Median: The middle value of the array when sorted. If the number of elements is even,
the median is the average of the two middle values.
Mean (Average): The sum of the numbers divided by the number of elements.
Range: The difference between the maximum and minimum values in the array.
Variance: A measure of the spread of the numbers in the array. It is the average of the
squared differences from the mean.
Standard Deviation: The square root of the variance, providing a measure of the spread
of the values.
Formulas:
The variance ( ) is calculated as:
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 6 of 24
4 Mode: 2
1223 Median: 2
Mean: 2.0
Range: 2
Variance: 0.50
Standard Deviation: 0.71
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 7 of 24
8 Mode: 8 9
8 8 9 10 9 8 10 9 Median: 9
Mean: 8.88
Range: 2
Variance: 0.61
Standard Deviation: 0.78
3 Mode: 4
446 Median: 4
Mean: 4.67
Range: 2
Variance: 0.67
Standard Deviation: 0.82
5 Mode: 2 3
12233 Median: 2
Mean: 2.2
Range: 2
Variance: 0.56
Standard Deviation: 0.75
Output the array after each operation. Perform no changes if index i is out of bounds.
5 123545
12345 13545
1 134
35 734
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 8 of 24
2
1
3
5
4
07
5
5 4132
54132 41532
2
0
1
25
5
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 9 of 24
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 10 of 24
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 11 of 24
2D square matrix.
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 13 of 24
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 14 of 24
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 15 of 24
Problem #3
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 16 of 24
Problem #4
Problem #5
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 17 of 24
Problem #6
Problem #7
Problem #7
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 18 of 24
Problem #8
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 19 of 24
Problem #9
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 20 of 24
Problem #10
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 21 of 24
Problem #11
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 22 of 24
Problem #12
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 23 of 24
Problem #13
Problem #14
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)
Page 24 of 24
Problem #15
Self-created Problems
Term Final Questions of BUET
Lab materials of CSE Lab of BUET
Taken Help from AI
C Programming Course,
Instructor – Md. Abdullah (EEE-19,BUET) , 01521706996(Whatsapp)