Element odd Number of times present in an array

Given an array of positive integers. All numbers occur even number of times except one number which occurs odd number of times. Find the number in O(n) time & constant space.

Example:
I/P = [1 2 3 3 2 3 1 3]
O/P = 3

#include<stdio.h>

main()
{

 int a[20],b[20],i,j,k,n,count;

  printf("Enter Number Of Element in Array:\n");
  scanf("%d",&n);

  printf("Read Array Element From User:");
   for(i=0;i<n;i++)
    {
      scanf("%d",&a[i]);
    }

    for(i=0;i<n-1;i++)
     {
      count=1;
      for(j=i+1;j<n;j++)
       {
        if(a[i]==a[j])
          {
         count++;
          }
       
       }
       if(count%2!=0)
         {
         printf("element '%d' odd Number of times present\n",a[i]);
         break;
         }
   
      }
   if(count%2==0)
   printf("None\n");
}

Related Posts