#define N 1001
void bubblesort(int *list,int len) //冒泡排序
{
int i,j
int temp
for(i=0i<len - 1i++)
for(j=0j<len-i - 1j++)
{
if(list[j+1]<list[j])
兆悄 {
族歼渣 temp=list[j+1]
list[j+1]=list[j]
list[j]=temp
}
}
}
int main(){
int num
int tar[N]
scanf("%d", &num)
while(num != 0){
for(int i = 0 i< 改慧num i++){
scanf("%d", &tar[i])
}
bubblesort(tar, num)
if(num % 2 == 0){
printf("%lg\n",(tar[num/2] + tar[num/2 - 1]) / 2.0)
}else{
printf("%lg\n", tar[num/2]*1.0)
}
scanf("%d",&num)
}
return 0
}
#include <棚陵stdio.h>毁耐void swap(int *p,int *q) {
int t
t=*p
*p=*q
*q=t
}
void sort(int a[],int n) {
int i,j,temp
for(i=0i<n-1i++) {
for(j=0j<n-i-1j++) {
if(a[j]>a[j+1])
swap(&a[j],&a[j+1])
}
}
}
int main() {
int a[] = {6,3,8,5,1}
int n = 5
int sum,i
sort(a,n)
n = (n+1) / 2 - 1 /纤和春/ -1 as array indexing in C starts from 0
printf("Median = %d ", a[n])
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)