[求助]关于求平均及其他
请看下列程序:#include <stdio.h>
void main()
{
double average(int *p);
int score[10]={90,91,92,93,94,95,96,97,98,99};
printf("The average:%f\n",average(score));
}
double average(int *p)
{
int sum=0,i;
for(i=0;i<10;i++)
sum+=*(p+i);
return sum/10;
}
此时可求得score的平均数;若用键盘输入向数组赋植则结果出错;怎么样才能既利用键盘输入向数组赋植,又能采用函数调用呢?先谢谢了!
[此贴子已经被作者于2007-7-19 16:20:04编辑过]
----------------解决方案--------------------------------------------------------
#include<stdio.h>
main(int n,int score[])
{int average();
int i,t;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&score[i]);
t=average(score,n);
printf("the average %d",t);
}
average(int *p,int n)
{int sum=0,i;
for(i=0;i<n;i++)
sum+=*(p+i);
return sum/n;
}
----------------解决方案--------------------------------------------------------