单选题 适中
#20522

下面枚举法查找最大值索引程序中,横线处应该填写的是() # include <iostream> using namespace std ; int main…

下面枚举法查找最大值索引程序中,横线处应该填写的是()

#include <iostream>
using namespace std;
int main() {
	int arr[] = {3, 7, 2, 9, 5};
	int maxIndex = 0;
	for (int i = 1; i < 5; i++) {
		__________________

	{
			maxIndex = i;
		}
	}
	cout << maxIndex;
	return 0;
}
未登录也能判分,登录后才会记录
答案与解析
正确答案:D
解析

根据代码表示, maxIndex存储最大值下标,所以横线处应判断当前值是否大于之前的最大值,所以选择 D 。(枚举法)