第1个回答 2013-05-17
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define ARRAYSIZE 10
#define GETMAXINDEX 0
#define GETMININDEX 1int GetMinMaxIndex(int *array,int iSize,int iMode)
{
int tmp=0;
for (int i=0;i!=iSize;++i)
{
if (iMode && (array[tmp]>array[i]))
tmp=i;
else if (!iMode && (array[tmp]<array[i]))
tmp=i;
}
return tmp;
} int main()
{
int array[ARRAYSIZE],i;
srand((unsigned int)time(NULL));
for (i=0;i!=ARRAYSIZE;++i)
array[i]=rand()%101;
puts("the Array is:");
for (i=0;i!=ARRAYSIZE;++i)
printf("%d ",array[i]);
printf("\nthe Max index is: %d\n",GetMinMaxIndex(array,ARRAYSIZE,GETMAXINDEX));
printf("the Min index is: %d\n",GetMinMaxIndex(array,ARRAYSIZE,GETMININDEX)); return 0;
}