c语言习题(指针)编写一个函数s(a,n),其中a是一个一维整型数组,n是数组长度,通过指针求数组中的平均数.(请用visual++版本解决)谢谢~但运行还是有错误Compiling...dghf.cC:\Program Files\Microsoft Vis

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/30 01:44:12
c语言习题(指针)编写一个函数s(a,n),其中a是一个一维整型数组,n是数组长度,通过指针求数组中的平均数.(请用visual++版本解决)谢谢~但运行还是有错误Compiling...dghf.cC:\Program Files\Microsoft Vis

c语言习题(指针)编写一个函数s(a,n),其中a是一个一维整型数组,n是数组长度,通过指针求数组中的平均数.(请用visual++版本解决)谢谢~但运行还是有错误Compiling...dghf.cC:\Program Files\Microsoft Vis
c语言习题(指针)
编写一个函数s(a,n),其中a是一个一维整型数组,n是数组长度,通过指针求数组中的平均数.(请用visual++版本解决)谢谢~
但运行还是有错误
Compiling...
dghf.c
C:\Program Files\Microsoft Visual Studio\MyProjects\gfdh\dghf.c(4) :error C2143:syntax error :missing ';' before ')'
执行 cl.exe 时出错.
dghf.obj - 1 error(s),0 warning(s)

c语言习题(指针)编写一个函数s(a,n),其中a是一个一维整型数组,n是数组长度,通过指针求数组中的平均数.(请用visual++版本解决)谢谢~但运行还是有错误Compiling...dghf.cC:\Program Files\Microsoft Vis
#include
using namespace std;
double s(int a[],int n)
{
long sum=0;
int* pa=a;
for(int i=0;i

int s(int a[],int n)
{int i,k=0;
int *p=a;
for(i=0;i<=n,i++)
k=k+*(p+i);
return(k/n);
}

不知道你要的是不是以下的这段代码~
double s(int a[],int n)
{
long sum=0;
int* pa=a;
for(int i=0;i {
sum+=*pa;
pa++;
}
return sum/n;
}