30 Easy C++ Programming Questions on the topic of Arrays


Q 1. Write a program to find the sum of all elements in an array.

Expected Output:

Enter number of elements: 5

Enter elements: 1 2 3 4 5

Sum of elements: 15

Q 2. Write a program to calculate the average of array elements.

Expected Output:

Enter number of elements: 5

Enter elements: 10 20 30 40 50

Average of elements: 30

Q 3. Write a program to find the maximum element in an array.

Expected Output:

Enter number of elements: 5

Enter elements: 3 5 7 2 8

Maximum element: 8

Q 4. Write a program to find the minimum element in an array.

Expected Output:

Enter number of elements: 5

Enter elements: 12 4 56 2 34

Minimum element: 2

Q 5. Write a program to count the number of odd and even numbers in an array.

Expected Output:

Enter number of elements: 6

Enter elements: 1 2 3 4 5 6

Number of odd numbers: 3

Number of even numbers: 3

Q 6. Write a program to reverse the elements of an array.

Expected Output:

Enter number of elements: 4

Enter elements: 10 20 30 40

Reversed array: 40 30 20 10

Q 7. Write a program to find the second largest element in an array.

Expected Output:

Enter number of elements: 5

Enter elements: 2 8 4 7 6

Second largest element: 7

Q 8. Write a program to find the sum of all even numbers in an array.

Expected Output:

Enter number of elements: 6

Enter elements: 1 2 3 4 5 6

Sum of even numbers: 12

Q 9. Write a program to find the sum of all odd numbers in an array.

Expected Output:

Enter number of elements: 6

Enter elements: 1 2 3 4 5 6

Sum of odd numbers: 9

Q 10. Write a program to count the number of positive and negative numbers in an array.

Expected Output:

Enter number of elements: 5

Enter elements: -1 2 -3 4 -5

Number of positive numbers: 2

Number of negative numbers: 3

Q 11. Write a program to count the frequency of each element in an array.

Expected Output:

Enter number of elements: 6

Enter elements: 1 2 2 3 1 4

Element frequencies:

1 occurs 2 times

2 occurs 2 times

3 occurs 1 time

4 occurs 1 time

Q 12. Write a program to find the median of an array.

Expected Output:

Enter number of elements: 5

Enter elements: 3 1 4 2 5

Median: 3

Q 13. Write a program to find the mode (most frequent element) of an array.

Expected Output:

Enter number of elements: 7

Enter elements: 1 2 2 3 3 3 4

Mode: 3

Q 14. Write a program to check if an array is sorted in ascending order.

Expected Output:

Enter number of elements: 4

Enter elements: 1 2 3 4

Array is sorted in ascending order.

Q 15. Write a program to find the largest element in each row of a 2D array.

Expected Output:

Enter number of rows and columns: 3 4

Enter elements: 1 2 3 4 5 6 7 8 9 10 11 12

Largest element in each row:

Row 1: 4

Row 2: 8

Row 3: 12

Q 16. Write a program to find the smallest element in each row of a 2D array.

Expected Output:

Enter number of rows and columns: 3 3

Enter elements: 5 2 8 3 6 1 7 4 9

Smallest element in each row:

Row 1: 2

Row 2: 1

Row 3: 4

Q 17. Write a program to find the transpose of a 2D matrix.

Expected Output:

Enter number of rows and columns: 2 3

Enter elements: 1 2 3 4 5 6

Transpose of the matrix:

1 4

2 5

3 6

Q 18. Write a program to find the sum of each column in a 2D array.

Expected Output:

Enter number of rows and columns: 3 3

Enter elements: 1 2 3 4 5 6 7 8 9

Sum of each column:

Column 1: 12

Column 2: 15

Column 3: 18

Q 19. Write a program to find the sum of each row in a 2D array.

Expected Output:

Enter number of rows and columns: 2 3

Enter elements: 1 2 3 4 5 6

Sum of each row:

Row 1: 6

Row 2: 15

Q 20. Write a program to check if two arrays are equal (i.e., they have the same elements in the same order).

Expected Output:

Enter number of elements: 4

Enter elements for first array: 1 2 3 4

Enter elements for second array: 1 2 3 4

Arrays are equal.

Q 21. Write a program to copy elements from one array to another.

Expected Output:

Enter number of elements: 4

Enter elements for first array: 1 2 3 4

Elements in the second array: 1 2 3 4

Q 22. Write a program to find the number of elements in an array greater than a given value.

Expected Output:

Enter number of elements: 5

Enter elements: 1 2 3 4 5

Enter the value: 3

Number of elements greater than 3: 2

Q 23. Write a program to merge two arrays into a single array.

Expected Output:

Enter number of elements in first array: 3

Enter elements for first array: 1 2 3

Enter number of elements in second array: 3

Enter elements for second array: 4 5 6

Merged array: 1 2 3 4 5 6

Q 24. Write a program to rotate an array to the right by a given number of positions.

Expected Output:

Enter number of elements: 5

Enter elements: 1 2 3 4 5

Enter number of positions to rotate: 2

Array after rotation: 4 5 1 2 3

Q 25. Write a program to find the difference between the largest and smallest elements in an array.

Expected Output:

Enter number of elements: 5

Enter elements: 1 2 3 4 5

Difference between largest and smallest elements: 4

Q 26. Write a program to count the frequency of each element in an array.

Expected Output:

Enter number of elements: 5

Enter elements: 1 2 2 3 3

Element frequencies:

1: 1

2: 2

3: 2

Q 27. Write a program to find the second largest element in an array.

Expected Output:

Enter number of elements: 5

Enter elements: 1 2 3 4 5

Second largest element: 4

Q 28. Write a program to reverse the elements of an array.

Expected Output:

Enter number of elements: 5

Enter elements: 1 2 3 4 5

Reversed array: 5 4 3 2 1

Q 29. Write a program to find both the minimum and maximum elements in an array.

Expected Output:

Enter number of elements: 5

Enter elements: 1 2 3 4 5

Minimum element: 1

Maximum element: 5

Q 30. Write a program to count the number of even and odd elements in an array.

Expected Output:

Enter number of elements: 5

Enter elements: 1 2 3 4 5

Number of even elements: 2

Number of odd elements: 3

Social Share

Bikki Singh

Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!

Programming Languages