Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
588 B
4
Indexable
Never
#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;
}
Leave a Comment