I'm working on a function that performs both an average output and the median of string of numbers. To perform the median calculation first I must be able to sort the functions properly, but I am having problems with it so far. This is what I have. Thanks everyone.
Code:#include <stdio.h> temp bubble_sort(int start, int end) int main (){ char buffer[512]; /* see previous program */ int entries, current; double input, average=0; printf("Please enter number of entries."); fgets(buffer, sizeof(buffer), stdin); sscanf(buffer, "%d", &entries); for (current=0; current<entries; ++current){ printf(" Please enter number %d: ", current+1); fgets(buffer, sizeof(buffer), stdin); sscanf(buffer, "%lf", &input); average= ((average*current) + input)/(current+1); /* sufficient for small sets */ /* printf("Current average: %g\n", average); */ /* debug */ getchar(); } printf("Average = %g\n", average); return 0; getchar(); } temp bubble_sort(int i, int n, int y, int x) { for (int i =0; i < n; i++) { int index_of_min = x; for (int y=i; y<i; y++) { if( array [index_of_min] >array [y] ) { index_of_min = y; } } int temp array =array[x]; array [x] = array [index_of_min]; array [index_of_min] = temp; getchar(); } }



LinkBack URL
About LinkBacks




). There is no policy against posting code (it is a programming forum), there's a policy discouraging people who ask others to do their homework for them. Providing examples or throwing out concrete ideas does not "keep people from learning".