Math, asked by oishimandal, 1 month ago


Write a program in java to input 10 different numbers and display the
greatest and the smallest number amongt them​

Answers

Answered by pds39937
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