Question: *Program is in C* Write a program that finds the majority element in an array if it exists. Majority element is the element which appears

*Program is in C*
Write a program that finds the majority element in an array if it exists. Majority element is the element which appears in more than half of the array locations. Declare an array of size 7 and read the array elements from the user. Then, compute and print the majority element if it exists. In an array of size 7, an element has to appear in at least 4 array locations in order to be majority element. Consider the following example. Majority element in this array is 3 since 3 appears 4 tunes and array size is 7 (0-6). Sample execution of the program for this array is given below In some cases majority element does not exist. Following example shows this. There is no majority element in this array. Maximum count in the array is 2. However. 4 is needed for majority. Sample execution of the program is given below One approach to this problem is to count how many times each element appears in the array. Find the maximum occurrence and compare it with 4. If maximum occurrence in the array is greaterthanorequalto 4 then corresponding element is majority. If maximum occurrence is
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
