我希望能夠找出矢量中的最高和最低元素,並找出當前高/低數字的位置/索引。 例如,矢量的索引/最大值/最小值<double> C++
vector<double> x;
std::cout << "Enter in #s: ";
double numbers;
std::getline(std::cin, numbers);
x.push_back(numbers);
比方說,用戶輸入4.3 1.0 2.99 43.5
我想要的結果說
The highest number is 43.5 at position 4
The lowest number is 1.0 at position 2
我想知道是否有任何的方式來實現這個代碼不使用min_element/max_element函數並使用for循環執行它?
我想用這樣的:
for (int i=0;i < x.size();i++)
if (//the number is less than) {
std::cout << "The lowest number is...... at position .....";
if (//the number is greather than) {
std::cout << "The highest number is......at position......";
哇,他們是awefully接近。 – RichardPlunkett