C語言編寫函數求數組中最小值?
#include "stdio.h"double fun(double a[],int n,int *max,int *min);/*函數原型聲明:其中a為數組,n為數組元素個數,max指向最大數,min指向最小數,函數返回值為平均值*/int main(){double b[10],aver;int x,y=10,max=0,*ma=&max,min=0,*mi=&min;for(x=0;x<y;x++){b[x]=x*(x-8.25)*0.1;printf("數%d=%f\n",x,b[x]);}aver=fun(b,y,ma,mi);printf("最大的數為第%d個數(%f),最小的數為第%d個數(%f),平均值為%f",*ma,b[*ma],*mi,b[*mi],aver);return 0;}double fun(double a[],int n,int*max,int*min){int i;double sum=0;double max1=a[0],min1=a[0];*max=0;*min=0;for(i=0;i<n;i++){if(a[i]>max1){*max=i;max1=a[i];}if(a[i]<min1){*min=i;min1=a[i];}sum=sum+a[i];}printf("sum=%f,n=%d\n",sum,n);return sum/n;}