#include int main() { // arr must not contain any element more than twice // if that may be the case, choose the alternative approach int arr[] = { 2, 4, 5, 6, 4, 8, 9, 2 }; int count = 0; for (int i = 0, size = sizeof(arr) / sizeof(int); i < size; i++) { int it = arr[i]; for (int i2 = i + 1; i2 < size; i2++) { int it2 = arr[i2]; if (it != it2) continue; count++; break; } } printf("%d duplicates found.", count); }