我讲方法里面的形参由数组改为了指向数组的指针,为什么运行的时候只能输入一个n值就结束了?代码如下,有点混乱,请求指点🙏
#include "stdio.h"
#define MAXNUM 20
typedef int ElemType;
void Create(ElemType *p,int *n){
int i;
printf("\nPlease input n=");
scanf("%d",&*n);
printf("Please input %d data:",*n);
for(i=1;i<=*n;i++)
scanf("%d",*(p+i));
}
void Maxmin(ElemType *p,int n,int *max,int *min,double *average){
int i,sum;
sum=0;
*average=0;
*max=*min=*(p+1);
for(i=1;i<=n;i++){
if(*(p+i)>*max) *max=*(p+i);
if(*(p+i)<*min) *min=*(p+i);
sum+=*(p+i);
}
*average=sum/(n*1.0);
}
void main(){
int i,n,max,min;
ElemType a[MAXNUM+1];
ElemType *p;
double average;
Create(p,&n);
printf("\nCreate is completed!\nThe data is:");
for(i=1;i<=n;i++)
printf("%4d",*(p+i));
Maxmin(p,n,&max,&min,&average);
printf("\nmax=%d min=%d\naverage=%f\n",max,min,average);
}