I wrote this code in C++ as part of a uni task where I need to ensure that there are no duplicates within an array:
// Check for duplicate numbers in user in
The following solution is based on sorting the numbers and then removing the duplicates:
#include int main() { int userNumbers[6]; // ... int* end = userNumbers + 6; std::sort(userNumbers, end); bool containsDuplicates = (std::unique(userNumbers, end) != end); }