I have a string of numbers. I need to check if the numbers on the edges are symmetric, meaning they have the same remainder when modulo by 2.
I have written a code which works, but I have something troubling my mind about that, after some failures I've come up with this code:
int PaliPair(char* st, int n)
{
if(n<=1) return 1;
return (*st%2 == *(st+n-1)%2) && PaliPair(st +1, n-2);
}
The question is, why do I have to return n-2
and not n-1
? I'm kinda confused of why it works. Any explanation would be highly appreciated. I think I'm missing something, perhaps the fact that the string ends with "\0"
which I need to conclude from that something.