C program to convert Gray code to Binary code

Simple C program to convert Gray code to Binary code

Code:

#include<stdio.h>
#include<conio.h>
main(){
int a[10],b[10],i,n;
clrscr();
printf("Enter the length of digit: ");
scanf("%d",&n);
printf("Now Enter the Binary Code");


for (i=0;i<n;i++){
scanf("%d",&a[i]);
}
b[0]=a[0];
for(i=1;i<n;i++){


if(a[i]==b[i-1])
{
b[i]=0;
}
else{
b[i]=1;


}
}
for(i=0;i<n;i++){
printf("%d",b[i]);
}
getch();
}

Comments

Popular posts from this blog

C program to evaluate Prefix Expression using Stack data structure

Servlet Program to Print Today’s Date and Time using refresh header

Java Program to Implement sorting algorithm using TCP on Server application