高手帮一下忙啊,用c++编程做下题,(急啊!)

来源:百度知道 编辑:UC知道 时间:2024/06/20 04:36:38
下面的程序中,调用了findmax()函数,该函数功能是寻找数组中最大元素,返回其位址值,同时将最大元素的下标通过参数传回调用处,编程实现findmax()函数。
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;
for(int i=0;i<sizeof(a)/sizeof(*a);i++)cout<<i<<"\t"<<&a[i]<<"\t"<<a[i]<<endl;
maxaddr=findmax(a,sizeof(a)/sizeof(*a),&idx);
cout<<"the index of maximum element is "<<idx<<endl //= *index 1
<<"the address of it is "<<maxaddr<<endl //= iptr a[1]
<<"the value of it is "<<a[idx]<<endl;} // 91
急啊.谢谢谢谢谢谢........

#include <iostream>
using namespace std;
int *findmax (int *array, int size, int *index);
int main (void)
{
int a[10] = { 33, 91, 54, 67, 82, 37, 85, 63, 19, 68 };
int *maxaddr;
int idx;
for (int i = 0; i < sizeof (a) / sizeof (*a); i++)
cout << i << "\t" << &a[i] << "\t" << a[i] << endl;
maxaddr = findmax (a, sizeof (a) / sizeof (*a), &idx);
cout << "the index of maximum element is " << idx << endl //= *index 1
<< "the address of it is " << maxaddr << endl //= iptr a[1]
<< "the value of it is " << a[idx] << endl;
return 0;
} // 91

int * findmax(int* array, int size, int* index)
{
int biggest=array[0], biggest_id = 0, i;
for(i = 0; i < size; i++)
{
if(biggest < array[i])