Question

In: Computer Science

Write a RIMS-compatible C-language for-loop that counts the number of times a bit of A is...

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.

Solutions

Expert Solution

#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;

    

}


Related Solutions

Write a function that counts the number of times a given integer occurs in a Linked...
Write a function that counts the number of times a given integer occurs in a Linked List. What is the time complexity of your algorithm? Justify your answer in python
Write a C program that counts the number of repeated characters in a phrase entered by...
Write a C program that counts the number of repeated characters in a phrase entered by the user and prints them. If none of the characters are repeated, then print “No character is repeated” For example: If the phrase is “full proof” then the output will be Number of characters repeated: 3 Characters repeated: f, l, o Note: Assume the length of the string is 10. ###Note: the output should print exactly as it is stated in the example if...
C language and it has to be a while loop or a for loop. Use simple...
C language and it has to be a while loop or a for loop. Use simple short comments to walk through your code. Use indentations to make your code visibly clear and easy to follow. Make the output display of your program visually appealing. There is 10 points deduction for not following proper submission structure. An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program that: Would read an input...
2.c++ if and loop statement Write a program that will count the number of even number...
2.c++ if and loop statement Write a program that will count the number of even number and odd numbers between two inputted numbers. Display the numbers and compute the sum and average of all the even numbers and the sum and average all the odd numbers. Sample outputs: Enter starting number:3 Enter starting number:4 Enter ending number:10 Enter ending number:10 odd numbers Even number 3 4 5 6 7 8 9 10 number of even numbers=4 number of even numbers=4...
C++ , Write an iterative routine that will have 2 queues. Loop for 100 times and...
C++ , Write an iterative routine that will have 2 queues. Loop for 100 times and in the loop roll two die and place the first result into the queue1 and second into queue2. Then dequeue the rolls one at a time from each, printing each pair, and count how many times two rolls either add up to 7 or are doubles (i.e. same value). After the queues are empty, print out the number of 7s and doubles. Assume srand...
C programming review excerises. 1. Write a function that counts the number of lines in a...
C programming review excerises. 1. Write a function that counts the number of lines in a file, using the following declaration: int countLines(char *filename) 2. Write a program that counts the number of words in a text file. Use the command-line arguments to read the name of the file. The syntax: countwords filename.txt 3. Write a program that counts the number of words starting with the first letter ‘T’ in a text file. Using commend line argument for the text...
Write a C program that counts the number of non white-space characters in an inputtext file....
Write a C program that counts the number of non white-space characters in an inputtext file. Program takes as command argument(s)the name of the input file (and the output file with option -f). Based on the option flags, it displays the output on the standard output, or writesthe output to an output file. The command format is as follows: command -f inputfile outputfile or, command -s inputfile -f indicates writing to an output file; -s indicates displaying the output on...
Write a C program that counts the number of odd numbers with using function count() within...
Write a C program that counts the number of odd numbers with using function count() within the set. The set has only one negative number which determines the end of set.
In C++ For this assignment, you will write a program to count the number of times...
In C++ For this assignment, you will write a program to count the number of times the words in an input text file occur. The WordCount Structure Define a C++ struct called WordCount that contains the following data members: An array of 31 characters named word An integer named count Functions Write the following functions: int main(int argc, char* argv[]) This function should declare an array of 200 WordCount objects and an integer numWords to track the number of array...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 2, … Fib(n) = Fib(n-1) + Fib(n-2). Place each value in the EAX register and display it with a call DumpRegs statement inside the loop For example: Fib(1) = 1, Fib(2) = 2, Fib(3) = Fib(1) + Fib(2) = 3, Fib(4) = Fib(2) + Fib(3)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT