数组最小值及下标.c 419 B

123456789101112131415161718192021
  1. #include <stdio.h>
  2. int main() {
  3. int n, i, min_index, min_value;
  4. scanf("%d", &n);
  5. int arr[999];
  6. for (i = 0; i < n; i++) {
  7. scanf("%d", &arr[i]);
  8. }
  9. min_value = arr[0];
  10. min_index = 0;
  11. for (i = 1; i < n; i++) {
  12. if (arr[i] < min_value) {
  13. min_value = arr[i];
  14. min_index = i;
  15. }
  16. }
  17. printf("%d\n%d", min_value,min_index);
  18. return 0;
  19. }