From 250d72804fc11bb5607102ad9fc64ef06f753b9d Mon Sep 17 00:00:00 2001 From: Umarul Farook <92313292+umarulfarook@users.noreply.github.com> Date: Wed, 27 Oct 2021 22:51:12 +0530 Subject: [PATCH] Create reoccurence.cpp --- CPP/reoccurence.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 CPP/reoccurence.cpp diff --git a/CPP/reoccurence.cpp b/CPP/reoccurence.cpp new file mode 100644 index 0000000..22bf506 --- /dev/null +++ b/CPP/reoccurence.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; + +int getOddOccurrence(int arr[], int arr_size) +{ + for (int i = 0; i < arr_size; i++) { + + int count = 0; + + for (int j = 0; j < arr_size; j++) + { + if (arr[i] == arr[j]) + count++; + } + if (count % 2 != 0) + return arr[i]; + } + return -1; +} + +int main() + { + int arr[] = { 2, 3, 5, 4, 5, 2, + 4, 3, 5, 2, 4, 4, 2 }; + int n = sizeof(arr) / sizeof(arr[0]); + cout << getOddOccurrence(arr, n); + return 0; + }