#include<stdio.h>#include<math.h>float fun(int a[],int n) //n是陣列a[]長度{ int i, k=0; float s=0,m=0; for(i=0;i<n;i++) { if (a[i]%2==0) { k++; m+=a[i];//偶數和 } else s+=a[i];//奇數和 } if(k>(n-k)) return m/k; else return s/(n-k); }int main(){ int a[]={80,70,96,78,68,66,74,85,86,100}; printf("%f\n", fun(a,10)); return 0; }
#include<stdio.h>#include<math.h>float fun(int a[],int n) //n是陣列a[]長度{ int i, k=0; float s=0,m=0; for(i=0;i<n;i++) { if (a[i]%2==0) { k++; m+=a[i];//偶數和 } else s+=a[i];//奇數和 } if(k>(n-k)) return m/k; else return s/(n-k); }int main(){ int a[]={80,70,96,78,68,66,74,85,86,100}; printf("%f\n", fun(a,10)); return 0; }