Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Declare an integer array with 10 elements, enter the group value from the keyboard, and find the maximum and minimum values ??and their corresponding subscripts.

#include

int

Declare an integer array with 10 elements, enter the group value from the keyboard, and find the maximum and minimum values ??and their corresponding subscripts.

#include

int

Declare an integer array with 10 elements, enter the group value from the keyboard, and find the maximum and minimum values ??and their corresponding subscripts.

#include

int getMaxValueIndex(int ??*p,int n)

{

int maxValueIndex = 0 ,i=0;

int maxValue = p[0];

for(i=0; i

{

if(maxValue < p[i])

{

maxValueIndex = i;

maxValue = p[i];

}

}

return maxValueIndex;

}

int getMinValueIndex(int ??*p,int n)

{

int minValueIndex = 0,i=0;

int minValue = p[0];

for(i=0; i

{

if(minValue > p[i])

{

minValueIndex = i;

p>

minValue = p[i];

}

}

return minValueIndex;

}

void main()

{

int a[10];

int i = 0;

int maxValue = 0,maxValueIndex = 0;

int minValue = 0,minValueIndex = 0;

printf("Please enter data:\n");

for( i = 0; i < 10; i++)

{

scanf("%d",&a[i]);

}

maxValueIndex = getMaxValueIndex(a,10);

maxValue = a[maxValueIndex];

minValueIndex = getMinValueIndex(a,10);

minValue = a[minValueIndex];

printf("Maximum subscript: %d corresponding maximum value: %d\n",maxValueIndex,maxValue);

printf("Min. Value subscript: %d corresponding minimum value: %d\n",minValueIndex,minValue);

}