In: Computer Science
Write a RIMS-compatible C-language for-loop that counts the number of times a bit of A is followed by a bit of the opposite parity (01 or 10) and writes the value to B. For example 00100110 has 4 cases: 00100110, 00100110, 00100110, 00100110.
#include <stdio.h>
int main() {
// your code goes here
printf("Enter number of digits in number: ");
int size;
scanf("%d",&size);
printf("\n");
int A[size];
printf("Enter the digits in number one by one: ");
for(int i=0;i<size;i++)
{
scanf("%d",&A[i]);
}
int B=0; //counts number of 01 or 10 occurences
for(int i=0;i<size-1;i++)
{
if((A[i]==0&&A[i+1]==1)||(A[i]==1&&A[i+1]==0))
B++;
}
printf("\n");
printf("The number of occurences of 01 or 10 in given number is: ");
printf("%d", B);
return 0;
}