All about programming in GNU/LINUX

BoolGorithm – 1 (hey guys i have started a project on Solving a boolean equation provided the minterms by the user to get a simplified equation using C , flow in and contribute to the code )

/*Project BoolGOrithm, this part of the code tells u the no.of.ones in the supplied minterms */
/*21/9/2011*/
//FRom 22-00//
#include<stdio.h>
#include<stdlib.h>
int main()
{
 int n,size,i,j,k,f,num,arrsize;

 printf("\nEnter the no.of.Input variables: ");
 scanf("%d",&n);
 printf("\nEnter no.of.Minterms Available: ");
 scanf("%d",&size);
 arrsize=(1<<n)-1;
  if(size>arrsize)
   {
    printf("\nInvalid Input");
    exit(EXIT_FAILURE);
   }
 int minterms[arrsize];
 printf("\nEnter the Min terms: ");
 for(i=0;i<size;i++)
 {
  scanf("%d",&minterms[i]);
  if(minterms[i]>arrsize)
   {
    printf("\nInvalid Input");
    exit(EXIT_FAILURE);
   }
 }
for(j=0;j<size;j++)
{
 num=0;
 for(i=n-1;i>=0;i--)
 {
  k=(minterms[j]& (1<<i));
  if(k)
   num++;


 }
  printf("\n\nThe minterm is %d,    no.of.ones is %d ",minterms[j],num);
}
return 0;
}
//23-50 110 Minutes of coding 


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s