Aashish sharma Sharma Aashish sharma Sharma - 1 year ago 105
C Question

Creating NOR/NAND gate with a loop

I want to implement a boolean NAND/NOR gate. Problem is I no of inputs to the gate I learn on the fly in the code itself i.e I dont know in advance how many inputs it may have. Following is the code for OR. But I cant figure out a way to do it for NOR/NAND. What should be initial value for result? Is there a way around?

result=0; //non controlling value for OR
for(i = 0; i < fin; i++)
result=(result | value);
final_value = result;

Answer Source

Have you tried doing AND/OR first (by taking the initial value as 1/0) and then taking its compliment?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download