I created a c program (as practice exercise for myself) that displays the median of a given array. Note that this is only a test program. I am trying to make a program that asks the user to fill in the array(what I did is to add a set of pre-defined number of elements in my program). Here's the program:
CODE
#include <iostream.h>
int main(int argc, char* argv[])
{
int arr[]={1,2,3,4,5,6};
int size=sizeof(arr)/sizeof(int);
int index=size/2;
float median=-1;
if((index % 2) == 0)
median=arr[index];
else
median=(float) (arr[index] + arr[index - 1]) / 2;
return 0;
}
I was unable to continue with it. How do I change the program so that it will:
>instead of a pre-defined given elements in the array, it will ask the user to enter the number that will fill in the array.
>it will sort the given array from highest to lowest and determine the median.
I'm actually a beginner in C program so I'm having troubles with the sorting algorithm. Thanks in advance.