Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Problem in finding the mode of a number in an array
Hi, I have got a problem as follows:
[b]The mode of an array of numbers is the number [i]m[/i] in the array that is repeated most frequently. If more than one number is repeated with equal maximal frequencies, there is no mode. Write a program that accepts an array of numbers and returns the mode or an indication that the mode does not exist[/b]
For this I have written the following code:
/* Question C.c (too long to write)
Compiler: Turbo C++ 3 */#include#define
int mode (int arr[MAX])
int i=0, j, t=0, p=1;
for (j=1; j<=MAX; j++)
/*else if (p==t)
int i, f;
for (i=1; i<=MAX; i++)
printf("Enter a number: ");
printf("The maximal frequency of the inputted array is: %d", f);
However, in case of
[code] if (p==t) [/code]
it always comes true and the return value is termed 0. However, without that statement and the condition that there cannot be a '0 mode' the program works fine.
Thanks in advance.