各位大虾,帮帮忙吧,总是出现内存错误啊
题目是要输入班级每个人分数,然后输出最高分,最低分,平均分,必须用指针实现,而且只能有一个函数编译时没有错误,但是一运行就有错误报告
#include<stdio.h>
int main()
{
void deal_with(int a,int *p_a,int *p_ma,int *p_mi,float *p_ave);
int n,a[30],i,max,mini;
float average,*pointer_ave;
int *pointer_a,*pointer_max,*pointer_min;
printf("Please input the number of student\n");
scanf("%d",&n);
printf("Please input the score\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
pointer_a = a;
pointer_max = &max;
pointer_min = &mini;
pointer_ave = &average;
deal_with(n,pointer_a,pointer_max,pointer_min,pointer_ave);
printf("%d,%d,%f\n",max,mini,average);
return(0);
}
void deal_with(int a,int *p_a,int *p_ma,int *p_mi,float *p_ave)
{
int sum=0,max=0,mini=0;
for(max=*p_a,mini=*p_a;p_a<p_a+a;p_a++)
{
if(*p_a >= max)
{
max=*p_a;
}
if(*p_a <= mini)
{
mini=*p_a;
}
sum=sum+*p_a;
}
*p_ma=max;
*p_mi=mini;
*p_ave=sum/(float)a;
}