fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6. const size_t size = 7;
  7. int array[size] = { 70, 20, 60, 40, 10, 30, 40 };
  8. std::sort(&array[0], &array[size]);
  9.  
  10. for (size_t i = 0; i < size; ++i)
  11. std::cout << array[i] << " ";
  12. std::cout << endl;
  13.  
  14. // lowest:
  15. std::cout << "Lowest: " << array[0] << std::endl;
  16.  
  17. // duplicate check
  18. // skip 1 and use backwards-looking checks, this saves us having
  19. // to do math in the loop condition.
  20. for (size_t i = 1; i < size; ++i) {
  21. if (array[i] == array[i - 1])
  22. std::cout << (i - 1) << " and " << i << " both contain " << array[i] << std::endl;
  23. }
  24. return 0;
  25. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
10 20 30 40 40 60 70 
Lowest: 10
3 and 4 both contain 40