Sunday, January 10, 2010

Permute function in draw the truth table program

void permute(int n)
{
                int
in=10,i=0,A[100],j,a,b,t,B[100],m,k,l,test,move=0,num=0,c,d=0,top=-1,value1,value2,value,opns[100];
                printf("The
truth table is\n\n");
                for(j=0;os[j]!='';j++)
                {
                                if(isalpha(os[j])!=0)
                                {printf("%c ",os[j]);}
                }
                printf("Y\n");
                while(in>0)//Resolving
the number into digits.
                {
                                A[i]=in%10;
                                in=in/10;
                                i++;
                }
                for(a=0;a<i;a++)//Sorting
the digits in the ascending order using bubble sort.
                {
                                for(b=0;b<=i-a;b++)
                                {
                                                if(A[b]>A[b+1]
&& b+1<i)
                                                {
                                                                t=A[b];
                                                                A[b]=A[b+1];
                                                                A[b+1]=t;
                                                }
                                }
                }
                //printf("\nThe
possible permutations are:\n");//Permutation logic starts.
                for(j=0;j<n;j++)//Initializing
the answer array.
                {
                                B[j]=A[0];
                }
                while(move<n)//move
counts the number of times the pointer moves towards the left.
                {
                                for(j=0;j<i;j++)
                                {
                                                B[n-1]=A[j];
                                                d=0;
                                                top=-1;
                                                for(l=0;os[l]!='';l++)
                                                {
                                                                if(isalpha(os[l])!=0)
                                                                {
                                                                                top++;
                                                                                opns[top]=B[d];
                                                                                d++;
                                                                }
                                                                else
                                                                {
                                                                                value1=opns[top];
                      
                                                         //printf("\n%d",value1);
                      
                                                         top--;
                       
                                                        value2=opns[top];
                       
                                                        //printf("\n%d",value2);
                       
                                                        top--;                             
                       
                                                        if(os[l]=='+')
                      
                                                         {
                          
                                                                     if(value1==1 ||
value2==1)
                                                                                                {value=1;}
                                                                                                else
                                                                                               {value=0;}                                            
                       
                                                        }
                                                                                //else if(os[j]=='-')
                       
                                                        //{value=value1-value2;}
                       
                                                        else
if(os[l]=='.')
                       
                                                        {
                         
                                                                      if(value1==1
&& value2==1)
                                                                                                {value=1;}
                                                                                                else
                                                                                                {value=0;}
                       
                                                        }
                      
                                                         //else if(os[j]=='/')
                       
                                                        //{value=value2/value1;}
                       
                                                        //printf("\n%d",value);
                                                                                top++;
                       
                                                        opns[top]=value;
                                                                }
                                                }                              
                                               
for(d=0;d<n;d++)
                                                {
                                                                printf("%d ",B[d]);
                                                }
                                                printf("%d\n",value);
                                                num++;
                                }
                                m=n-1;
                                move=0;
                                while(m>=0
&& B[m]==A[i-1])
                                {
                                                m--;
                                                move++;
                                }
                                for(k=0;k<i;k++)
                                {
                                                if(B[m]==A[k])
                                                break;
                                }
                                B[m]=A[k+1];
                                while(m!=n-1)
                                {
                                                m++;
                                                B[m]=A[0];
                                }
                }
}

Enter the expression: (A+B).(C+D)
The truth table is
  A  B  C   D  Y
  0   0   0   0   0
  0   0   0   1   0
  0   0   1   0   0
  0   0   1   1   0
  0   1   0   0   0
  0   1   0   1   1
  0   1   1   0   1
  0   1   1   1   1
  1   0   0   0   0
  1   0   0   1   1
  1   0   1   0   1
  1   0   1   1   1
  1   1   0   0   0
  1   1   0   1   1
  1   1   1   0   1
  1   1   1   1   1

No comments:

Post a Comment