Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <array>
- #include <string>
- #include <algorithm>
- #include <iomanip>
- using namespace std;
- int main()
- {
- const size_t arraySize = 5;
- array< int, arraySize > duplicate = {};
- for (int i = 0; i < arraySize; ++i)
- {
- int tempNumber;
- cout << "Enter a number between 10 and 100: ";
- cin >> tempNumber;
- if (tempNumber <= 100 && tempNumber >= 10)
- {
- bool dup = binary_search( duplicate.begin(), duplicate.end(), tempNumber);
- cout << "Number " << tempNumber << (dup ? " is a duplicate!" : " was stored in array." );
- (dup ? tempNumber : duplicate[i] = tempNumber);
- cout << endl;
- }
- else
- {
- cout << "Number is out of range!" << endl;
- }
- }
- sort(duplicate.begin(), duplicate.end());
- for( int x : duplicate)
- cout << x << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement