红色是题目给出的,编程实现findmax()函数,寻找数组最大元素.该元素的下标通过参数返回,并返回其地址值.
#nclude<iostream.h>
int *findmax(int *array,int size,int *index);
void main()
{
int a[10]={33,91,54,67,82,37,85,63,19,68};
int *maxaddr;
int idx;
maxaddr=findmax(a,sizeof(a)/sizeof(*a),&idx);
cout<<"the index of maximum element is "<<idx<<endl
<<"the address of it is "<<maxaddr<<endl
<<"the value of it is "<<a[idx]<<endl;
}
int *findmax(int *array,int size,int *index)
{
int max=0,idx;
size=sizeof(array)/sizeof(int);
for((*index)=0;(*index)<size;(*index)++)
if(array[*index]>max)
max=array[*index];
idx=*index;
return 0;
}
上面是我写的,是否符合题意?程序是否正确?