i
and j
will never be equal when the item count is even. You're swapping both halves of the array in that case, which ultimately produces the original sequence. Perhaps instead of using that weird logic for your swapping loop, just use the relationship of i
and j
as the primary condition:
void swap(int a[N])
{
int i, j;
for (i = 0, j = N - 1; i < j; i++, j--)
{
a[i]=a[i]+a[j];
a[j]=a[i]-a[j];
a[i]=a[i]-a[j];
}
}