You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 23, 2025. It is now read-only.
int num = 31;
int count = 0;
while (num > 0)
{
if (num & 1 == 1) // like %2 for odd
{
++count;
}
num = num>>1; // like divide by 2
}
cout << "Count : " << count << endl;
Find the odd occuring element
#include<stdio.h>// Function to return the only odd// occurring elementintfindOdd(int arr[], int n)
{
int res = 0, i;
for (i = 0; i < n; i++)
res ^= arr[i];
return res;
}
intmain(void)
{
int arr[] = { 12, 12, 14, 90, 14, 14, 14 };
int n = sizeof(arr) / sizeof(arr[0]);
printf("The odd occurring element is %d ",
findOdd(arr, n));
return0;
}
output :
The odd occurring element is 90