C++ 代码
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, x[1000], min = 1001, minIndex = -1;
cin >> n;
for (int i = 0; i < n; i++){
cin >> x[i];
//下面的循环第一次必然会进入,因为min的值1001比任何数都要大
if (x[i] < min) min = x[i], minIndex = i;
}
printf("Minimum value: %d\n", min);
printf("Position: %d", minIndex);
if (minIndex == -1) cout << "bug : minIndex == -1" << endl;
return 0;
}