#include <stdio.h>
int main() {
int A[10];
for (int i = 0; i < 10; i++) {
scanf("%d", &A[i]);
}
int max = A[0];
int max_pos = 1;
int min = A[0];
int min_pos = 1;
for (int i = 1; i < 10; i++) {
if (A[i] > max) {
max = A[i];
max_pos = i + 1;
}
if (A[i] < min) {
min = A[i];
min_pos = i + 1;
}
}
printf("%d %d %d %d\n", max, max_pos, min, min_pos);
return 0;
}
This program reads 10 integers into an array, then finds the maximum and minimum values along with their positions (1-based indexing). It prints these four values.
- The initial positions are set to 1, but the first element is at index 0. Consider whether the initial position values should match the first element's actual position.
- The code uses 1-based positions (i+1) inside the loop, but the initial positions are set to 1 without checking if the first element is actually the max or min. Think about how to correctly initialize the positions to match the first element.