## 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

### 2 responses

1. i think that the following piece of code must be replaced
arrsize=(1<<n)-1;
by
arrsize=1<<n;
because there must be an array that can accept 2 power n values (worst case of a user) and not one less… for example, if there are 3 variables, the array minterm ll have size of 7 and not 8…
and did u try the program?? i have doubts over the initialization of the array minterms in the middle of the code…

September 22, 2011 at 11:43 am

• Yup , realized the mistake ………got it corrected 🙂 Thank u

September 26, 2011 at 2:17 am