Close

Generating Gray codes

Gray code is a sequence of n-bit binary code where each pattern differs with the previous pattern by only one bit. For example 2-bit gray code is shown below. 00 01 11 10 Now we have two write a program to generate such a sequence for the given value (n). One algorithm to generate gray…

Generating the counting sequence

Given an integer N, we have to generate the nth sequence of the following pattern. “1” “11” as the previous item contains one instance of 1. “21” as the previous entry contains two 1’s. “1211” as the previous entry contains one 2 and one 1. Following is the program which generates such a sequence. It…