I was able to compile the code. but when i try to run it. it prints the arranged number in the array then terminates. it does not print the median.
what do you think might have caused this? i dunno whats the problem.
#include <stdio.h>
#include <stdlib.h>
int median(const int [], const int);
int main(){
int array[50];
int i, b, t;
int num;
printf("This program gets the median of an array.\n");
printf("Press ^Z [CTRL + Z] after the last inputed number\n\n");
printf("How many numbers do you want to input? ");
scanf("%d", &num);
for (i=0; i<50; i++){
scanf("%d", &array[i]);
}
-----from here: i should've put this in the function definition part but there are errors(in red).. but when i placed it here, there are no errors but then i does not work properly----- for(i=1; i<num; i++)
for(b=num-1; b>=i; --

{ //arrange numbers in array based on value
if(array[b-1] > array[b]){
t=array[b-1];
array[b-1] = array[b]; array[b]=t;
}
}
for(t=0; t<num; t++){ //print numbers in order
printf("%d\n", array[t]);
}
-----end of the part that i wanted to put in funct def---- printf("The median is %d", median(array,50));
return 0;
}
int median (const int array[], const int size){ //function definition
int median = array[50];
int num;
median = num/2;
if(num%2 ==1){ //for odd num(size of array)
median = array[median];
}
else { //for even num
median = (array[median]+array[median-1])/2;
}
return num;
}
help me guys!
This post has been edited by azshteeg: 7 Aug, 2008 - 02:31 AM