binary truth table creation

#include<stdio.h>
#include<math.h>

void main()
{
int r,c,i=0,count[10],rCount[10],colBit[10],bit[2]={0,1},col,row;
printf("enter the no. Of bit whose truth table you want :");
scanf("%d",&col);
row=pow(2,col);

for(c=1;c<=col;c++)
{
count[c-1]=pow(2,col-c);
rCount[c-1]=0;
colBit[c-1]=0;
}


for(c=0;c<col;c++)
{
printf("%d",count[c]);
}
printf("\n\n");

for(r=0;r<row;r++)
{
for(c=0;c<col;c++)
{
if(rCount[c]<count[c])
{
printf("%d",bit[colBit[c]]);
rCount[c]++;
}
else
{
rCount[c]=0;
if(colBit[c]==1)
{
colBit[c]=0;
}
else if(colBit[c]==0)
{
colBit[c]=1;
}
c--;
}
}
printf("\n");
}
}

Post a Comment

0 Comments