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)

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

what type of questions

1697


i=20;k=0; for(j=1;k-i;k+=j<10?4:3) { cout<

1415


Plese get me a perfect C++ program for railway/airway reservation with all details.

3427


What is abstraction and encapsulation?

569


just right the logic of it 1--> If few people are electing then every time ur candidate should win 2--> arrange books in box, if box carry weight == books weight then take another box..... find the no of box required.

6485






Are polymorphisms mutations?

699


What is a class and object?

598


hi, this is raju,iam studying b.tech 2nd year,iam want know about group1 and group2 details, and we can studying without going to any instutions? please help me.

1541


Explain the concepts involved in Object Oriented programming.

633


any one please tell me the purpose of operator overloading

1965


What is the full form of oops?

607


What language is oop?

591


What is the point of oop?

654


What is difference between oop and pop?

613


if i have same function with same number of argument but defined in different files. Now i am adding these two files in a third file and calling this function . which will get called and wht decide the precedence?

2753