#include <stdio.h>
int validate_checksum(int *mem, int n) {
int sum = *mem;
for(int* p = mem + 1; p <= (mem + (n - 2)); p++){
sum ^= *p;
}
if(sum == *(mem + (n - 1))){
return 1;
}
return 0;
}
int main() {
int n, arr[100];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int result = validate_checksum(arr, n);
printf("%d", result);
return 0;
}
Solving Approach
There is a typo in the problem Example-1. The sum should be 40 not 60!