Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

You have one base class virtual function how will call that function from derived class?

4 Answers  


Do you know about multiple inheritance?

1 Answers   Motorola,


Which language is not a true object oriented programming language?

0 Answers  


What do you mean by binding of data and functions?

3 Answers  


Which is faster post increment or pre increment ? and in which cases should u use either - to increase speed?

4 Answers   EA Electronic Arts,


Why is static class not inherited?

0 Answers  


design class for linked list and include constructor,destructor,insert option. struct node { int node; struct node &ptr; }

1 Answers   HSBC,


how to find the largest of given numbers in an array

2 Answers  


What is encapsulation in oops?

0 Answers  


What is Agile methodology?

20 Answers   ABC, Accenture, College School Exams Tests, Inmar, Microsoft, Sapient,


What are the advantages of polymorphism?

0 Answers  


What is Virtual Keyword?

9 Answers   IBM, NA,


Categories