- A+

Category：Languages

Lets say I have an boolean array with 5 bool variables all being true

`bool boo[10]; for(int i = 0; i < 5; i++){ boo[i] = true; } `

I want them all compared into one NAND logic gate at once because my problem is if I always compare two variables and compare the merged boolean to the i+1 boolean variable. This gives a wrong result.

` bool NANDGate(bool array[]){ bool at; for(int i = 1; i < 5; i++){ if(i == 1){ at = !(array[i-1] && array[i]); }else{ at = !(at && array[i]); } } return at; } // result here is true even though it should be false `

What I want is a right result when I put every variable from boo into a NAND gate so something maybe that looks like this:

`bool func(bool array[]){ // some loop result = !(array[0] && array[1] && array[2] && array[3] && array[4]); return result; } // result here would be false `

actually it doesn't have to look like that just maybe a solution that has a right result like the above would have.

EDIT: So many great solutions I thank you all

The following should do it:

`bool NANDGate(bool array[]) { for(int i = 0; i < 5; i++) { if (!array [i]) return true; } return false; } `