Untitled
unknown
plain_text
2 years ago
588 B
9
Indexable
#include <stdio.h>
int main() {
int n;
printf("Enter the number of elements in the sequence: ");
scanf("%d", &n);
int sequence[n];
printf("Enter the sequence (0s and 1s only):\n");
for (int i = 0; i < n; i++) {
scanf("%d", &sequence[i]);
}
int parity = 0;
for (int i = 0; i < n; i++) {
parity ^= sequence[i];
}
if (parity == 0) {
printf("The sequence has even parity (output: 1)\n");
} else {
printf("The sequence does not have even parity (output: 0)\n");
}
return 0;
}Editor is loading...
Leave a Comment