I can’t seem to find the bug, help: I’m trying to input n, followed by n integers. Then output these n integers’ median. n is odd and positive. n is less than 1 million.
Sample Input
5 37 28 21 44 49
Sample Output
37
#include <stdio.h>
#include <stdlib.h>
#define INTEGERS 6
int numbers[6];
int compare(const void * a, const void * b) {
return ( *(int*) a - *(int*) b);
}
int main() {
int n, i;
for (i = 0; i < 6; i++) {
printf("Enter numbers:");
scanf("%d", numbers[i]);
}
qsort(numbers, INTEGERS, sizeof (int), compare);
for (n = 0; n < INTEGERS; n++) {
printf("%d ", numbers[n]);
}
printf("\n%d ", numbers[INTEGERS / 2]);
return 0;
}
Scanf requires a memory address, not a value.
Try: