M
M
madwayz13372018-11-27 00:51:45
C++ / C#
madwayz1337, 2018-11-27 00:51:45

How to count the number of rows in an array with at least one zero? And how to make the inversion of the main diagonal of the matrix?

Something I can't figure out. There is a 4x4 matrix and you need to print the number of rows that have at least 1 zero.

int iZeroStringsCount = 0;
    for (int iTable = 0; iTable < SIZE - 1; iTable+) {
      for (int iString = 0; iString < SIZE - 1; iString++) {
        if (b[iTable][iString] == 0) {
          ++iZeroStringsCount;
        }
      }
    }

How to reverse the order of the elements of the main diagonal of the same matrix?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Shvedov, 2018-11-27
@mmmaaak

I give advice, judging by the assignment, you are only studying programming, studying somewhere or on your own - it doesn’t matter. The main goal of such tasks is not to teach you how to work with matrices specifically, but to teach you how to look for a solution on your own, and it’s not for nothing that not some abstract entities are often used in such tasks, but matrices that can easily be worked with outside the conditions of the problem. I recommend taking a notebook, drawing the original matrix, drawing next to the result that is supposed to be obtained, identifying: what has changed, which elements of the matrix have changed their coordinates and how, write out separately what has changed and how, identify a pattern, taking into account what is most often with matrices work in a cycle, suggest what the condition of the cycle should be, so that this matrix can be changed based on the patterns obtained, but if you find this condition, but you don’t know how to write it specifically in C++ or something else, they will be happy to help you, because it will be clear that you have worked on the task, and because the lack of experience was just a little underestimated. And very few people want to paint for you the whole decision from scratch, and there will be no sense from this.
PS. And with strings and zeros, stop the second loop if you have already found at least one zero, you don’t need to check further.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question