c语言高手来啊 bubble sort method

来源:百度知道 编辑:UC知道 时间:2024/06/04 15:39:28
急求答案!!! 高手帮帮忙啊!!!

Using pointers, write a program that reads in 10 real numbers in an array before calculating
the average and the median of the 10 input numbers. The median of a set of n values x is the
middle value (the (n+1)/2 th value when the n numbers are sorted in increasing order.
Use modular programming to write a function that calculates the average of n given numbers,
a function that sorts an array of n elements in increasing order and a function that determines
the median of an array of n elements.
Hint: To sort the array elements, use the bubble sort method, which works as follows: Make
n passes through the array. On each pass, successive pairs of elements are compared. If a
pair is in increasing order (or if the values are identical), we leave the values as they are. If a
pair is in decreasing order, their values are swapped in the array.

#include <stdio.h>
void main()
{
int a[10],i,max,temp;
printf("输入十个数:");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("\n");
max=0;
for(i=0;i<10;i++)
{

if(a[i]>max)
{
temp=max;
max=a[i];
}
}
printf("你输入的十个数中最大的为:%d\n",max);

}