I want to generate a truth table for a given input. Suppose if I give input 2, the output will be
10 01 11 00
if input 3, output will be
111 000 110 101 011 100 001 010
I have a piece of code
for $a (1, 0){
for $b (1, 0){
for $c (1,0) {
for $d ( 1,0)
{
print "$a $b $c $d";
print "\n";
}
}
}
}
print "\n";
The code above is for 4.
I do not know how to do this without recording a few loops. Here for a value of 2, I need to write two for loops, etc.
can any body tell me how to configure this code for multiple input values.
Any help would be much appreciated
source
share