#include<stdio.h>
main()
{
int arr[5], max, min, i, j, k;
printf("Please enter five integers:\n");
for(i=0; i<5; i++)
scanf("%d", arr[i]);
min = arr[0];
for(i = 0; i < 5; i++)
if(arr[i] < min)
{
min = arr[i];
j = i;
}
max = arr[0];
for(i = 0; i < 5; i++)
if(arr[i] > max)
{
max = arr[i];
k = i;
}
arr[j] = max;
arr[k] = min;
printf("The index of minimum value is: %2d\n", k);
printf("The index of maximum value is: %2d\n", j);
for(i = 0; i < 5; i++)
printf("%5d", arr[i]);
printf("\n");
}
时间: 2024-10-23 02:38:22