主题:本人菜鸟,程序有通过,但结果不对。忘高手解决
使用软件WIN-TC,程序通过后,可是计算结果并不正确,不知哪里错误了,忘高手解决,谢谢
#include <stdio.h>
void main()
{
float average(float a[],int n);
float s_1[5]={1,2,1,4,5};
float s_2[3]={10,15,30};
printf("s1 pj %f\n",average(s_1,5));
printf("s2 pj %f\n",average(s_2,3));
getch();
}
float average(float a[],int n)
{
float aver,sum;
int i;
sum=0;
for(i=0;i<n;i++);
sum=sum+a[i];
aver=sum/n;
return (aver);
}
#include <stdio.h>
void main()
{
float average(float a[],int n);
float s_1[5]={1,2,1,4,5};
float s_2[3]={10,15,30};
printf("s1 pj %f\n",average(s_1,5));
printf("s2 pj %f\n",average(s_2,3));
getch();
}
float average(float a[],int n)
{
float aver,sum;
int i;
sum=0;
for(i=0;i<n;i++);
sum=sum+a[i];
aver=sum/n;
return (aver);
}