用数组加上指针三组数各自的平均数,为什么只能求出第一组?
#include<stdio.h>#define SIZE 10
float ave(float * start,float * end);
int main(void)
{
float mark1[SIZE]={78,85,89,87,58,98,74,85,98,65};
float mark2[SIZE]={98,58,98,94,96,85,86,84,84,96};
float mark3[SIZE]={89,68,68,78,85,84,86,84,82,89};
double n1,n2,n3;
n1 = ave(mark1,mark1 + SIZE);
n2 = ave(mark2,mark2 + SIZE);
n3 = ave(mark3,mark3 + SIZE);
printf("三组的平均成绩为:%2.1f %2.1f %2.1f\n",n1,n2,n3);
return 0;
}
float ave(float * start,float * end)
{
float ave,total;
while(start < end)
{
total += * start;
start++;
}
ave = total/SIZE;
return ave;
}