Need help to write one c++ code.

How to write a c++ program which will accept binary numbers as matrix from user and also get particular position of element from matrix and then print how many 0's and 1's are neighboring to selected position element?
With std::cin, std::cout and a bidimensional array.
define binary number. Is this a so-called binary file / byte stored values, or actual input of things like 01101010 ?


for this, rather than compare, you can just add up the neighbors, eg

101

010

111

sum is either 5 or 6 depending on whether you want to include the center location or not. that is how many 1s so 9(or 8) - (5 or 6) gives the number of zeros, eg ignoring the middle its 5 1s and 8-5 is 3 zeros.

which leads to probably wanting a container of Booleans. If the 'matrix' is small enough, eg < 64x64, you can represent it with integers and do bit logic. It all just depends on details we don't have
Last edited on
Topic archived. No new replies allowed.