-
Notifications
You must be signed in to change notification settings - Fork 0
/
Saptarshi.c
60 lines (54 loc) · 1 KB
/
Saptarshi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<stdio.h>
#include<malloc.h>
#include<math.h>
#include <string.h> /* strcat */
#include <stdlib.h> /* strtol */
int *array,counter = 0;
void byte_to_binary(int x,int n)
{
static char b[20];
b[0] = '\0';
int z;
for (z = 128; z > 0; z >>= 1)
{
strcat(b, ((x & z) == z) ? "1" : "0");
}
int i = 8-n , j = 0;
while(i<8){
//bi[j] = b[i];
printf("%c",b[i]);
i++;
//j++;
}
}
int greycode(int n )
{
int k,i;
array[counter++]=0;
array[counter++]=1;
for(i=1 ; i < n; i++){
k = counter -1;
while(k>=0){
array[counter++] = array[k--] | 1<<i;
}
}
}
void main()
{
int n,i, j = 0 ;
char * bi;
printf("\nEnter n\n");
scanf("%d",&n);
array = (int*)malloc(pow(2,n)*sizeof(int));
greycode(n);
printf("\n------------------------greycode------------------------------\n");
for(i=0;i<counter;i++){
byte_to_binary(array[i],n);
/*while(j != 2)
{
printf("%c",bi[j]);
j++;
}*/
printf("\n");
}
}