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…

## Finding the integer square root of a number

How do we implement a function to find the integer square root of a number? For example int_sqrt(4) = 2, int_sqrt(10) = 3. (We have to take floor of the actual square root) A simple method is to iterate i from 1 to N/2 and keep checking until i2 < N, and whenever i2 >=…

## Setting the matrix elements to zero

Given a matrix of size m * n, write a program to fill zero in ith row and jth column if matrix[i][j] is zero. For example let us consider the following matrix. [    6 0 2   1 3 4   5 9 0 ] It should transform to the following. [    0…