0% found this document useful (0 votes)
26 views4 pages

Array Practice Questions

Uploaded by

Romessa Ali
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)
26 views4 pages

Array Practice Questions

Uploaded by

Romessa Ali
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
You are on page 1/ 4

Array Practice Questions

1. C++ Program To Find Maximum Difference Between Two Elements in an Array.


Example Arr is {10, 15, 90, 200, 110};
Max difference is 190

2. C++ Program to put even & odd elements of an array in 2 separate arrays.
Enter the size of array AR
6
Enter the elements of the array
34
56
78
90
12
39
The elements of OAR are
39
The elements of EAR are
34
56
78
90
12

3. C++ program to Insert an Element in the Sorted Array


Enter how many elements
5
Enter the elements
76
90
56
78
12
Input array elements are
76
90
56
78
12
Sorted list is
12
56
76
78
90
Enter the element to be inserted
61
Final list is
12
56
61
76
78
90
4. C++ program to Delete an Element from an Array from kth index

Runtime Test Cases


Testcase 1: In this case, the index of the element to be deleted is “3”
Enter the size of the array: 5
Enter the elements of the array:
arr[0] = 8
arr[1] = 4
arr[2] = 9
arr[3] = 6
arr[4] = 2
Enter the index of the element to be deleted: 3
The array after deleting the element is: 8 4 9 2

Testcase 2: In this case, the index of the element to be deleted is “6”


Enter the size of the array: 4
Enter the elements of the array:
arr[0] = 10
arr[1] = 4
arr[2] = 6
arr[3] = 1
Enter the index of the element to be deleted: 6
Deletion is not possible in the array.

5. C++ Program to Cyclically Permute the Elements of an Array


Enter the value of the n = 4
Enter the numbers
3
40
100
68
Cyclically permuted numbers are given below
40
100
68
3

6. C++ Program to Print all Non Repeated Elements in an Array


Enter size of the array: 6
Enter 6 elements of an array: 12
10
4
10
12
56

The array after removing duplicates is: 12 10 4 56


7. C++ Program to Find Missing Numbers in Array
Enter elements into array :
1
2
3
5
6
Missing element is : 4

8. C++ Program to Find Missing Numbers in an Array of Size N-1 with Numbers[1,N]
enter the range of array
9
enter a[0]element into the array:1
enter a[1]element into the array:5
enter a[2]element into the array:2
enter a[3]element into the array:7
enter a[4]element into the array:3
enter a[5]element into the array:4
enter a[6]element into the array:10
enter a[7]element into the array:9
enter a[8]element into the array:6
The missing number -> 8

9. C++ Program to Find Odd Occurring Elements in an Array


10. C++ Program to Find Mode of an Array
Enter the limit
10
Enter the set of numbers
1 2 2 3 4 5 5 6 7 8

Mode = 2 5

11. C++ Program to Split the Array and Add First Part to the End
Enter the value of n
4
enter the numbers
3
678
345
876
Enter the position of the element to split the array
3
The resultant array is
876
3
678
345
12. C++ Program to Segregate 0s and 1s in an Array
Original array = {0, 1, 0, 1, 1, 0}
segregated array is 0 0 0 1 1 1

13. C++ Program to Find the Largest Sum of Contiguous Subarray of an Array
Type the length of the array
8
type the elements of the array
-1
-5
5
3
-2
5
4
1

The largest contiguous subarray is 5 3 -2 5 4 1


The sum of the largest contiguous subarray is 16

14. C++ Program to Merge Two Sorted Array Elements


Enter the size of the first array: 3
Enter the elements of the first array:
12
18
23
Enter the size of the second array: 3
Enter the elements of the second array:
13
19
27
The merged array is:
12 13 18 19 23 27

15. C++ Program to Print all Repeated Elements with Frequency in an Array
Array {5, 10, 10, 2, 1, 4, 2};
duplicate elements present in the given array are 10 2

You might also like