Untitled
unknown
plain_text
a year ago
995 B
6
Indexable
#include <stdio.h> int main() { int x[50], y[50]; int n, i, j, k, count; printf("Enter size of the bit string: "); scanf("%d", &n); printf("Enter the bit string (0's & 1's): "); for (i = 0; i < n; i++) { scanf("%d", &x[i]); } i = 0; j = 0; while (i < n) { if (x[i] == 1) { count = 1; y[j] = x[i]; j++; for (k = i + 1; k < n && x[k] == 1 && count < 3; k++) { y[j] = x[k]; j++; count++; } if (count == 3) { y[j] = 0; j++; } i = k - 1; // Update i to skip over the consecutive 1s } else { y[j] = x[i]; j++; } i++; } printf("Result of Bit Stuffing: "); for (i = 0; i < j; i++) { printf("%d", y[i]); } printf("\n"); return 0; }
Editor is loading...
Leave a Comment