I want to build a binary matrix (with 1 and 0 entries) with all possible combinations, say for example if n is the number of entries of one row of the matrix, then 2^n is the total number of different entries in the matrix.(adsbygoogle = window.adsbygoogle || []).push({});

For instance, for n=3, 2^n = 8, so we would have the following matrix

[ 1 0 0

0 1 0

0 0 1

1 1 0

1 0 1

0 1 1

1 1 1

0 0 0 ]

I am writing a C++ code but I have not figured out how to make it. Any suggestions?

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Binary matrix

**Physics Forums | Science Articles, Homework Help, Discussion**