1. Wrie a function which returns the most frequent number
in a list of integers. Handle the case of more than one
number which meets this criterion.
public static int[] GetFrequency(int[] list)



1. Wrie a function which returns the most frequent number in a list of integers. Handle the case o..

Answer / vadivel t

Hi,
The below code shall serve the purpose of the question but
it will work only for single digit elements. (ie., array
should contain sigle digit nos)

#include<stdio.h>
#include<conio.h>

int main()
{
int local[10] = {0,0,0,0,0,0,0,0,0,0};
int a[100];
int i, j, repeat, length, big;
int result[13];

printf("ENTER NO OF ELEMENTS IN THE ARRAY\n");
scanf("%d", &length);
printf("ENTER THE ELEMENTS IN THE ARRAY\n");
for(i = 0; i< length; i++)
{
scanf("%d", &a[i]);
}

for(i = 0; i<length; i++)
{
repeat = 0;

for(j = 0; j<length; j++)
{
if(a[j] == i)
{
repeat++;
}
}
local[i] = repeat;
//printf("%d \n", repeat);
}

big = 0;
for(i = 0; i<length; i++)
{
if(big < local[i])
{
big = local[i];
}
}
/*put the data in result buffer*/
for(i = 0, j = 0 ; i<length; i++)
{
if(local[i] == big)
{
result[++j] = i;

}
}
result[0] = j;
result[++j] = big;

printf("No(s) ");
for(i = 0; i< result[0]; i++)
{
printf("%d, ", result[i+1]);
}
printf("Repeats %d times\n", result[j]);
getch();
}

Is This Answer Correct ?    6 Yes 19 No

Post New Answer

More OOPS Interview Questions

How to overload new operator in c++

2 Answers  


What is destructor give example?

0 Answers  


#include <iostream> using namespace std; struct wow { int x; }; int main() { wow a; wow *b; a.x = 22; b = &a; a.x = 23; cout << b->x; return 0; }

1 Answers  


How can i write a code in c# to take a number from the user and then find all the prime numbers till the number entered by the user.

4 Answers   NIIT, TCS,


What is class and example?

0 Answers  






What does oop mean in snapchat?

0 Answers  


how to get the oracle certification? send me the answer

0 Answers   Oracle,


to find out the minimum of two integer number of two different classes using friend function

0 Answers  


what is pointers

7 Answers   Exilant,


What is a class oop?

0 Answers  


What is encapsulation oop?

0 Answers  


what is diff between .net 1.1 and .net 2.0

4 Answers  


Categories