This recursive function must return 1
if the sum of all digits of the num
is even, if the sum is odd - return 0
.
Please explain me what it exactly does in details and how the NOT operator works in this particular example. I haven't seen yet NOT on the recursive call and it confused me a bit.
int func(int num) {
if (num < 10) {
if (num % 2 == 0) {
return 1;
} else {
return 0;
}
}
if ((num % 10) % 2 == 0) {
//roughly clear, but I'll be glad to receive some opinions about that to be sure
return func(num / 10);
} else {
return !func(num / 10); //this line is not clear for me
}
}