#include #include /*Input: Integer array and its size * Output: None * Return: None * Notes: Function to sort the integers entered by user */ void sort(int arr[], int * size) { /*initializes local variables needed to run bubble sort*/ int i; int j; int tmp; /*bubble sort implementation*/ for(i=0; i<(*size-1); i++) { for(j=0; j<(*size-1); j++) { if (arr[j]>arr[j+1]) { tmp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = tmp; } } } } /*Input: Integer array, array size, 2 ints to hold large/small values * Output: None * Return: None * Notes: BS function determines the largest and smallest integers in * the array after the array has been sorted */ void bs(int arr[], int * size, int * largest, int * smallest) { *largest=arr[*size-1]; *smallest=arr[0]; } /*Input: Integer array, array size, float to hold the mean value * Output: None * Return: None * Notes: Function to calculate the mean of the stored integers */ void mean(int arr[], int * size, float * avg) { /*initializes local variables for mean calculation*/ int count=0; float sum=0; /*while loop to sum all elements in array*/ while(count<*size) { sum = sum + arr[count]; count++; } /*divides sum by size to determine mean, and assigns to avg*/ *avg=sum / *size; } /*Input: Integer array, array size, char array to hold the median value * Output: None * Return: None * Notes: Function to calculate the median of the stored integers */ void median(int arr[], int * size, char med[]) { /*initializes local variables needed to save median as a string*/ int med1; int med2; /*if/else block to check if number of elements is odd or even *to determine if there is one value for median or two */ if(*size%2==0) { /*finds and stores median values in temp int*/ med1=arr[*size/2-1]; med2=arr[*size/2]; /*stores the median values in the string med*/ sprintf(med, "%d, %d", med1, med2); } else { /*finds and stores median value in a temp int*/ med1=arr[*size/2]; /*stores the median value in the string med*/ sprintf(med, "%d", med1); } } /*Input: Integer array, array size, char array to hold the median value * Output: Sorted list of integers, as well as mean, median, total * elements and largest/smallest integers in the entered list * Return: Type - int, value - 0 * Notes: Main method that handles input and output, and calls other * functions to perform calculations */ int main() { /*int that determines the grow rate for dynamic array*/ int grow=10; /*initializes array and allocates starting memory*/ int * arr=(int *)malloc(sizeof(int)*grow); /*initializes holding int that enables integers entered by user to stored in array*/ int tmp=0; /*int that tracks the number of elements in the array*/ int size=0; int count=0; float avg=0; int largest=0; int smallest=0; /*string that stores value for median*/ char med[80]; /*initial prompt to enter integers*/ printf("\nPlease enter the integers to be processed\n"); /*while loop to store integers entered by user in an array*/ while(scanf("%d", &tmp)==1) { arr[size]=tmp; size++; /*these two lines enable memory allocated to the array arr to grow dynamically*/ grow+=10; arr=(int *)realloc(arr, sizeof(int)*grow); } /*calls sort function to use bubble sort to sort array*/ sort(arr, &size); printf("\n-------------------------------------------\nsorted integers: "); /*while loop to print out newly sorted array*/ while(count