1. ## Finding mode!

I am encountering problem to find mode in my program.. Can anyone fix this? Thanks!

Code:
```#include<stdio.h>
#include<conio.h>
#define SIZE 5
void main()            /*Declaration of the main function*/
{
int a[50],i,j,k,m,z,temp,median;
float s=0.00,mean, mode;
printf("Enter the integers :-\n");
for(i=0;i<SIZE;i++)
scanf("\n %d",&a[i]);

for(i=0;i<SIZE-1;i++)
for(j=0;j<SIZE-1-i;j++)
if(a[j]<a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}

/*Finding highest and lowest and mode*/
double prevNumber = a[0] - 1;
int timesUsed, mostUsed = -1;
for ( i = 0; i < SIZE; i++ ) {
if (prevNumber == a[i]) {
timesUsed++;
} else {
prevNumber = a[i];
timesUsed = 1;
}
{
if (timesUsed > mostUsed)
mostUsed = timesUsed;
mode = a[i];
printf("\n\n%s\n%s\n%s\n%s", "***********", "   Mode", "***********");
printf("\n\tMode=%d\n", mode);
}
printf("\n%s\n%s\n%s\n%s", "****************************", "   Lowest and Highest Value", "****************************");
printf("\n\tHighest=%d\n", a[0]);
printf("\tLowest=%d\n",a[SIZE-1]);

/*Printing the sorted array*/
printf("\n The number in sorted order is :=\n");
for(i=0;i<SIZE;i++)
{
printf("\n%d",a[i]);
s=s+a[i];
}

/*Finding mean*/
printf ("\n\n%s\n%s\n%s\n", "***********", "   Mean", "***********");
printf ("\n\tTotal=%f",s);
mean=s/SIZE;
printf("\n\tMean=%f",mean);

/*Finding median*/
printf("\n\n%s\n%s\n%s\n%s", "***********", "   Median", "***********");
if((SIZE%2)==0)
printf("\n\tMedian=%d\n",a[(SIZE/2)-1]);
else
printf("\n\tMedian=%d\n",a[((SIZE+1)/2)-1]);

return 0;

}
}```

2. I'm not familiar with your sorting logic. Is there a particular reason not to use this simple selection sort?

Code:
```for(i = 0; i < SIZE - 1; i++)   {
for(j = i + 1; j < SIZE; j++)   {
if(array[i] > array[j]   {
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}```
I have never seen a simpler sorting block of code, that could run any faster. Once you start mucking around with sorting code, it's easy to simply break the logic. It may no longer sort correctly, or it may simply take longer to sort than it should. To confound matters worse, it may sort one set of data correctly, but not sort all sets of data correctly.

In your mode code, are you saving the value of the most common digit, as you go through the array and check each number?

Code:
```next = highest =  repeat = mode = 0;
for each number in the array   {
if(array[number] == last_number)   {
repeat++;
if(repeat > highest)   {
highest = repeat;
mode = array[number];
}
}
else   //the number was not repeated
repeat = 0;
last_number = array[number];
}```
I haven't tried this, but it should get started on the right path. Do verify your sorting is working properly though. The above will require a sorted array.