输入n个整数(int范围),存放在数组中,输出其最大数所在位置(n<=10000)。 Sample Input 5 67 43 90 78 32 Sample Output 3 c++代码
时间: 2024-04-13 21:31:18 浏览: 116
Sure! Here's a C++ code snippet that takes input for n and an array of n integers, and then finds the position of the maximum number in the array:
```cpp
#include <iostream>
int main() {
int n;
std::cin >> n;
int arr[10000];
for (int i = 0; i < n; i++) {
std::cin >> arr[i];
}
int maxIndex = 0;
for (int i = 1; i < n; i++) {
if (arr[i] > arr[maxIndex]) {
maxIndex = i;
}
}
std::cout << maxIndex << std::endl;
return 0;
}
```
You can run this code and input the number of integers followed by the integers themselves, and it will output the position of the maximum number. In the example you provided, it would output `3`.
阅读全文