2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by supergeek60
0

Its all good i figured it out -- heres the code:

#include <stdio.h>
#include <stdlib.h>

void insertionSort(float numbers[], int array_size);

int main() {
    int array_size;

    printf("how many numbers? ");
    scanf("%i", &array_size);

   float numbers[array_size]; 
   float modes[array_size/2]; 

   float num;
   int i;

   printf("numbers:\n");
   for(i = 0; i < array_size; i++) {
         scanf("%f", &num);
        numbers[i] = num;
    }

    insertionSort(numbers, array_size);

    float temp;
    int mode;
    mode = 0;



for(i = 0; i < array_size; i++) {
   if(i != 0) {
    temp = numbers[i];
    if(temp == numbers[i-1]) {
        mode ++;
        modes[mode] = numbers[i];
    }
   }
}

int z = mode + 1;

for(i = 1; i < z; i++) {
    printf("     %f\n", modes[i]);
}





scanf("%d", &i);

}

void insertionSort(float numbers[], int array_size)
{
  int i, j, index;

  for (i=1; i < array_size; i++)
  {
    index = numbers[i];
    j = i;
    while ((j > 0) && (numbers[j-1] > index))
    {
      numbers[j] = numbers[j-1];
      j = j - 1;
    }
    numbers[j] = index;
  }
}

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.