Question

Write a program to find the element of an array, which occurs maximum number of times and its count. The program should accep

in C language

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
int main(void){
  
int max=-1,ele=0,array[5];
printf("Enter array elements (array size:5):");

for(int i=0;i<5;i++){
scanf("%d",&array[i]);
}
for (int i = 0; i < 5; i++) {
int count = 0;
for (int j = 0; j < 5; j++) {
if (array[i]==array[j])
count++;
}
if (count >= max){
max = count;
ele=array[i];
}
}
if(max>-1){
printf("Max occuring elements: %d, count: %d",ele,max);
}
else
{
printf("Not exist");
}
}

Add a comment
Answer #2
#include <stdio.h>
void main()
{
int maxm=-1,element=0,array[5];
printf("Enter array elements (array size:5):");
for(int i=0;i<5;i++){
scanf("%d",&array[i]);
}
for (int i = 0; i < 5; i++) {
int cnt = 0;
for (int j = 0; j < 5; j++) {
if (array[i]==array[j])
cnt++;
}
if (cnt >= maxm){
maxm = cnt;
element=array[i];
}
}
if(maxm>-1){
printf("Max occuring elements: %d, cnt: %d",element,maxm);
}
else
{
printf("No repeting element is present");
}
}


answered by: Shivani Sharma
Add a comment
Know the answer?
Add Answer to:
in C language Write a program to find the element of an array, which occurs maximum...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MIPS CODE required to write an assembly program to find the maximum of an array of integers by...

    required to write an assembly program to find the maximum of anarray of integers by doing the following:1. Prompt user to input array size n (n <= 10)2. Prompt user to input element values of array A one by one3. Display the result on the console.This program must at least include one function. The main program will read the valuesof the array (as user inputs the element values) and stores them in the memory (datasegments section) and at the end...

  • Write a C Language Program that will ask the user how many elements the "maxminarray" will...

    Write a C Language Program that will ask the user how many elements the "maxminarray" will have. Read the elements from user and fill the "maxminarray” with it. Find maximum value and minimum value in maxminarray See the output below: Input number of elements of the array :6 Input 6 elements for the maxminarray : element [0]: 23 element [1] : 56 element [2] : 11 element [3]: 78 element [4]: 21 element [5]: 400 The Maximum element is :...

  • In need this in C language! Write a program that declares a 40 element array of...

    In need this in C language! Write a program that declares a 40 element array of type double. Initialize the array so that: the first 10 elements are equal to the square of the index variable the next 10 each elements is equal to three times the index variable the next 10 each element is equal to the sum of an element in the first 10 + an element in the second 10 the last 10 each element is equal...

  • In C only Please! This lab is to write a program that will sort an array...

    In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

  • In C language Write a program that includes a function search() that finds the index of...

    In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...

  • Please do in C and only use stdio.h. Write a program that reads n integers into...

    Please do in C and only use stdio.h. Write a program that reads n integers into an array, then prints on a separate line the value of each distinct element along with the number of times it occurs. The values should be printed in ascending order. Turn in your code and input/result together. Suppose, for example, that you input the values -7 3 3 -7 5 5 3 as the elements of your array. Then your program should print -7...

  • - Write a program that performs several operations on an array of positive ints. The program...

    - Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...

  • How do I write this in the c++ language? 1. (10 points) Write a program to...

    How do I write this in the c++ language? 1. (10 points) Write a program to implement Heapsort. The input should be an array of size at least 15. Have the user enter the values or you can specify your own array (unsorted). The output should be the final sorted array AND print out the values in the max heap (just the heap, NOT the full array) after each MAX-HEAPIFY (after BUILD- MAX-HEAP i.e. don't print output in BUILD-MAX-HEAP) in...

  • Write a program in C to count the frequency of the selected element of an array. Sample input/output dialogue

    Sample input/output dialogue: Enter array element limit: 5 Enter 5 elements in the array: 1 1 2 3 1 Enter element to search for frequency : 1 Result is : 1 occurs 3 times

  • Using Matlab Write a program which will: a. Accept two numbers from the user m and...

    Using Matlab Write a program which will: a. Accept two numbers from the user m and n b. Define an array with the dimensions a(n,m) and fill it with random numbers in the range of -100 to 100 inclusive. c. Provide the user the following menu from which he can select: 1. Sum of all elements in the array. Print the result. 2. Sum of the element in a row that he’ll specify. Print the result. 3. Sum of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT