   # A list contains a set of numbers, one number presents once and other numbers present even no. of times.

69 views

A list contains a set of numbers, one number presents once and other numbers present even no. of times. Find out the number that occurs once in the list. posted Oct 26, 2015

+1 vote

Following C program gives the expected.

`````` #include<stdio.h>
int main()
{
int numList[] = { 12, 12, 14, 14, 15, 15, 16 };
int diffNum = 0;
int i;
int totalNum  = sizeof(numList)/sizeof(numList);

for (i=0; i < totalNum; i++)
{
diffNum ^= numList[i];
}

printf("Different Number = [%d]", diffNum);

return 0;
}
`````` answer Oct 27, 2015 by

## include <stdio.h>

int main()
{
int a[] = {1,3,3,1,3,4,4,6,1,6,1};
int n = sizeof(a)/sizeof(a);
int i = 0, j = 0;

``````for(i = 0; i < n; i++){
for(j = i+1; j < n; j++){
if(a[i] == a[j]){
a[j] = -a[j];
break;
}
}
if(i != n-1){
printf("i %d\n",i);
if(a[i] != a[j]){
if(a[i] == -(a[j])){
continue;
}else if(a[i] < 0){
continue;
}else{
printf("Unique Number [%d]\n",a[i]);
break;
}
}
}else{
printf("Unique Number [%d]\n",a[i]);
break;
}
}
return 0;
``````

} answer Nov 24, 2015
Similar Questions