Given an array, Print the number which occurs only once and all others occurs twice or more than twice.
For example:
If the input array is
1 1 2 2 3
then the result is 3 as it occurs only once but all other elements 1 & 2 occurs twice in the array.
Implementation:
For example:
If the input array is
1 1 2 2 3
then the result is 3 as it occurs only once but all other elements 1 & 2 occurs twice in the array.
Implementation:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
 int i,*a,n,xr=0;
 
 /* Get the number of elements of the array */
 scanf("%d",&n);
 
 /* dynamically allocate memory block of n integers and store the initial address in a */
 a=(int*)malloc(sizeof(int)*n);
 
 /* Get the elements of the array */
 for(i=0;i<n;i++)
  scanf("%d",(a+i));
 /* finding the odd element */
 /* Get the xor result of all the values which will have the final result as odd element*/
 for(i=0;i<n;i++)
  xr^=*(a+i);
 
 printf("the odd element is %d",xr);
 return 0;
}