w3resource

C++ Array: Exercises, Practice, Solution

C++ Array [30 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

1. Write a C++ program to find the largest element of a given array of integers.
Click me to see the sample solution

2. Write a C++ program to find the largest three elements in an array.
Click me to see the sample solution

3. Write a C++ program to find the second largest element in an array of integers.
Click me to see the sample solution

4. Write a C++ program to find the k largest elements in a given array of integers.
Click me to see the sample solution

5. Write a C++ program to find the second smallest elements in a given array of integers.
Click me to see the sample solution

6. Write a C++ program to find all elements in an array of integers that have at least two significant elements.
Click me to see the sample solution

7. Write a C++ program to find the most frequent element in an array of integers.
Click me to see the sample solution

8. Write a C++ program to find the next more powerful element of every element of a given array of integers. Ignore those elements that have no greater element.
Click me to see the sample solution

9. Write a C++ program to sort a given unsorted array of integers, in wave form.
Note: An array is in wave form when array[0] >= array[1] <= array[2] >= array[3] <= array[4] >= . . . .
Click me to see the sample solution

10. Write a C++ program to find the smallest element missing from a sorted array.
Click me to see the sample solution

11. Write a C++ program to update every array element by multiplication of the next and previous values of a given array of integers.
Click me to see the sample solution

12. Write a C++ program to rearrange the elements of a given array of integers in a zig-zag pattern.
Note: The format zig-zag array in form a < b > c < d > e < f.
Click me to see the sample solution

13. Write a C++ program to separate even and odd numbers in an array of integers. Put all even numbers first, and then odd numbers.
Click me to see the sample solution

14. Write a C++ program to separate 0s and 1s from a given array of values 0 and 1.
Click me to see the sample solution

15. Write a C++ program to rearrange a given sorted array of positive integers .
Note: In final array, first element should be maximum value, second minimum value, third second maximum value , fourth second minimum value, fifth third maximum and so on.
Click me to see the sample solution

16. Write a C++ program to sort a given array of 0s, 1s and 2s. In the final array put all 0s first, then all 1s and all 2s last.
Click me to see the sample solution

17. Write a C++ program to sort (in descending order) an array of distinct elements according to the absolute difference of array elements and with a given value.
Click me to see the sample solution

18. Write a C++ program to move all negative elements of an array of integers to the end of the array. This is done without changing the order of the positive and negative elements of the array.
Click me to see the sample solution

19. Write a C++ program to find a number that occurs an odd number of times in a given array of positive integers. In the array, all numbers occur an even number of times.
Click me to see the sample solution

20. Write a C++ program to count the number of occurrences of a given number in a sorted array of integers.
Click me to see the sample solution

21. Write a C++ program to find the two repeating elements in a given array of integers.
Click me to see the sample solution

22. Write a C++ program to find the missing element from two given arrays of integers except one element.
Click me to see the sample solution

23. Write a C++ program to find the element that appears once in an array of integers and every other element appears twice.
Click me to see the sample solution

24. Write a C++ program to find the first repeating element in an array of integers.
Click me to see the sample solution

25. Write a C++ program to find and print all common elements in three sorted arrays of integers.
Click me to see the sample solution

26. Write a C++ program to find and print all distinct elements of a given array of integers.
Click me to see the sample solution

27. Write a C++ program to find the number of pairs of integers in a given array of integers whose sum is equal to a specified number.
Click me to see the sample solution

28. Write a C++ program to arrange the numbers in a given array in a way that the sum of some numbers equals the largest number in the array.
Click me to see the sample solution

29. Write a C++ program to find the second lowest and highest numbers in a given array.
Click me to see the sample solution

30. Write a C++ program to find the third largest string in a given array of strings.
Click me to see the sample solution

CPP Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/cpp-exercises/array/index.php