下面是我写的,void sort 那部分好像不行,无法把数组从小到大打印不出,大侠们帮忙看看啊.其他部分也顺便看看
#include
#include
<stdlib.h>void
generate (int, int b[], int);void
sort(int c[], int);void
mean(int d[],int);void
median( int e[], int);int
main (){
int seed,size,a[100],j;printf(
"enter a seed\n");scanf(
"%d",&seed); while( seed >0){
do{
printf(
"enter a size\n");scanf(
"%d", &size);}
while (size<1 || size >100);generate( seed, a, size);
sort(a, size);
mean(a, size);
median(a ,size);
printf("enter a seed\n");
scanf("%d",&seed);
}
return 0;}
void
generate (int s, int b[], int size){
int i,y;srand(s);
for(i=0; i<size; i++){
b[i]=rand() %10;
printf(
"%6d",b[i]);}
printf(
"\n");}
void
sort (int c[], int size) // 打印数组,从小到大排列{
int i, j,temp; for(i=0; i<size-1;i++){
for(j=i+1; j<size; j++){
if( c[i] > c[j]){
temp = c[i];
c[i] = c[j];
c[j] = temp;
}
}
}
for(j=j+1; j<size; j++)
printf(
"%d\t",c[j]);}
void
mean ( int d[],int size){
int total=0,i,m; for(i=0;i< size;i++)total += d[i];
m = total / size;
printf(
"mean is %d\n", m);}
void
median( int e[], int size){
int i,m1; for ( i=0; i<size; i++);m1= size /2;
printf(
"median is %d\n", m1);}