Search
 
SCRIPT & CODE EXAMPLE
 

C

generate n-bit gray code in c

#include <stdio.h>
#include <math.h>
int decimal_to_binary(int);
int main(void)
{
    int bits,gray;
    printf("What is the number of bits? ");
    scanf("%d",&bits);
    int max_num = pow(2,bits)-1;
    for(int j=0; j<=max_num; j++)
    {
        gray=j^(j>>1);
        printf("%d
",decimal_to_binary(gray));
    }
    return 0;
}
int decimal_to_binary(int num)
{
    int binary=0,i=0;
    while(num!=0)
    {
        int reminder = num%2;
        binary += reminder*pow(10,i);
        num/=2;
        i++;
    }
    return binary;
}
Comment

PREVIOUS NEXT
Code Example
C :: powershell search files for string 
C :: sleep in c programming 
C :: swapping of two numbers in c without temporary variable 
C :: c distance between 2 points 
C :: How to install npm in alpine linux 
C :: manifest orientation portrait 
C :: find factors of a number in c 
C :: c get file size 
C :: bash check if inside lxc 
C :: printf boo; 
C :: Numeri in ordine crescente C 
C :: bootstrap 5 modal not working vue js 3 
C :: prime numbers c 
C :: successeur d’un entier donné 
C :: libdvd-pkg: `apt-get check` failed 
C :: silicon valley 
C :: c number to string 
C :: how to create calculator with switch in c 
C :: malloc in c 
C :: c program for swapping of two numbers using temporary variable 
C :: C Passing string to a Function 
C :: array reference argument 
C :: c fopen 
C :: Fibonacci Series Program. in c 
C :: bootsrap textbox 
C :: int to double c 
C :: malloc 
C :: pop and push shows black screen which needs to be pressed back flutter 
C :: c language 
C :: c extern 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =