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

What is inheritance write a program to show use of inheritance?

0 Answers  


What causes polymorphism?

0 Answers  


What is and I oop mean?

0 Answers  


difference between structure and union.

2 Answers   ADP, Convergys,


Why do we use virtual functions?

4 Answers  






what is the sylabus for priliminaries?

0 Answers  


what is the difference between inter class and abstract class...?

0 Answers  


wht is ditch

0 Answers  


What is ambiguity in c++

4 Answers   Accenture, Mphasis,


How do you achieve polymorphism?

0 Answers  


suppose A is a base class and B is the derved class. Both have a method foo which is defined as a virtual method in the base class. You have a pointer of classs B and you typecast it to A. Now when you call pointer->foo, which method gets called? The next part of the question is, how does the compiler know which method to call?

3 Answers   EA Electronic Arts,


1. Strong name 2. how to prevent a class from being inherited 3. delegates 4. default modifier for interface 5. default modifier for class 6. base class for exception 7. diff bet trigger and view in sql 8. how to exchange values from one page to another page 9. can multiple catch block ll be executed at same time 10. can u store different data types in an array & array list 11. when we ll use trigger 12. try,catch,finally usage

2 Answers  


Categories