﻿ C exercises: Find the number occurring odd number of times in an array - w3resource

# C Exercises: Find the number occurring odd number of times in an array

## C Array: Exercise-34 with Solution

Write a program in C to find the number occurring odd number of times in an array.
All numbers occur even number of times except one number which occurs odd number of times.

Pictorial Presentation: Sample Solution:

C Code:

``````#include <stdio.h>

int findOddCountElem (int *arr1, int n )
{
int i, ResultXor = 0;
for(i = 0; i < n; i++)
{
ResultXor = ResultXor ^ arr1[i];
}
return ResultXor;
}

int main()
{
int i;
int arr1[] = {8, 3, 8, 5, 4, 3, 4, 3, 5};

int ctr = sizeof(arr1)/sizeof(arr1);
printf("The given array is :  ");

for(i = 0; i < ctr; i++)
{
printf("%d  ", arr1[i]);
}
printf("\n");

printf("Number of odd number occur(s) : %d times.\n", findOddCountElem(arr1, ctr));
return 0;
}
```
```

Sample Output:

```The given array is :  8  3  8  5  4  3  4  3  5
Number of odd number occur(s) : 3 times.
```

Flowchart : C Programming Code Editor:

Improve this sample solution and post your code through Disqus.

What is the difficulty level of this exercise?

﻿

Inviting useful, relevant, well-written and unique guest posts