#include
#include
#define N 10
void printarr(double a[],int n);
double maxnum(double a[],int n);
double average(double a[],int n);
int find(double a[],int n,double x);
void BubbleSort(double a[],int n);
int main()
{
double array[N],x;
int i,n;
double max;
double ave;
int pos;
do
{
printf("Please input n(1<=n<=10):\n");
scanf_s("%d",&n);
}while (n<1||n>N);
printf("Please input %f elements:\n",n);
for(i=0;i
printarr(array,n);
printf("Please input x be searched:\n");
scanf_s("%lf",&x);
pos=find(array,n,x);
if(pos
else
printf("Not present!\n");
max=maxnum(array,n);
ave=average(array,n);
BubbleSort(array,n);
printf("max element:%f\n",max);
printf("ave element:%f\n",ave);
printarr(array,n);
system("pause");
return 0;
}
void printarr(double a[],int n) //输出一维数组
{
int i;
printf("The elements are:\n");
for(i=0;i
printf("\n");
}
double maxnum(double a[],int n) //求一维数组中最大元素
{
int i;
double max;
max=a[0];
for(i=1;i
max=a[i];
return max;
}
double average(double a[],int n) //求一维数组平均值
{
int i;
double ave;
double sum=0.0;
for(i=0;i
sum+=a[i];
}
ave=sum/n;
return ave;
}
int find(double a[],int n,double x) //查找元素
{
int i=0;
while(i
if(x==a[i])
break;
i++;
}
return i;
}
void BubbleSort(double a[],int n) //完成一维数组的冒泡排序
{
int i,j;
double temp;
for(i=0;i
if(a[j] {
temp=a[j-1];
a[j-1]=a[j];
a[j]=temp;
}
}
好,找时间帮你看看