Need help finding a unique value in array
- by bardockyo
My code is complete minus one little flaw. It searches the array and prints out which values are unique, however it always counts the first entry as unique even if it is followed by the same value. Can anyone look at my code and tell me which part is messing this up because it is driving me crazy.
#include <stdio.h>
#define size 7
int main(void)
{
int array1[size], target, answer, found, x, k, prev, count =1, i;
printf("Please input %d integers: ", size);
scanf("%d", &target);
for(x = 0; x < size; x++)
{
scanf("%d", &array1[x]);
}
prev = array1[0];
for (i = 1; i < size; i++)
{
if (array1[i] == prev)
{
count++;
}
else
{
if (count < 2)
printf("%d=%d\n", prev, count);
prev = array1[i];
count = 1;
}
}
if (count < 2)
{
printf("%d=%d\n", prev, count);
}
return 0;
}