8_1.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:

C#编程

开发平台:

Visual C++

  1. //8_1
  2. #include <iostream.h>
  3. int* findmax(int* array, int size, int* index);
  4. void main()
  5. {
  6.   int a[10]={33,91,54,67,82,37,85,63,19,68};
  7.   int* maxaddr;
  8.   int idx;
  9.   maxaddr=findmax(a, sizeof(a)/sizeof(*a), &idx);
  10.   cout <<"the index of maximum element is " <<idx <<endl
  11.        <<"the address of it is " <<maxaddr <<endl
  12.        <<"the value of it is " <<a[idx] <<endl;
  13. }
  14. int* findmax(int* array, int size, int* index)
  15. {
  16.   *index=0;
  17.   for(int i=0; i<size; i++)
  18.     if(array[i]>array[*index])
  19.       *index=i;
  20.   return &array[*index];
  21. }