Write a program in java to input 10 different numbers and display the
greatest and the smallest number amongt them
Answers
Answered by
3
Step-by-step explanation:
#include <algorithm>
#include <iterator>
#include <iostream>
int main()
{
std::istream_iterator<int> it_begin(std::cin), it_end;
auto p = std::minmax_element(it_begin, it_end);
if (p.first != it_end)
std::cout << "min: " << *p.first << " max: " << *p.second;
}
Disclaimer:
Technicaly, this isn't required to work by C++ standard. The minimum iterator category required for minmax_element is ForwardIterator which stream iterators are not. Once an input iterator is dereferenced or incremented, its copies are no longer guaranteed to be dereferenceable or comparable to other iterators. It Works On My MachineTM. :)
Similar questions
Social Sciences,
2 months ago
English,
2 months ago
English,
2 months ago
Math,
4 months ago
English,
11 months ago