A
A
Andrey Rudenko2020-11-26 00:18:35
C++ / C#
Andrey Rudenko, 2020-11-26 00:18:35

How to select the entire matrix?

Good evening! I have one row of the matrix displayed, and I need to check the entire matrix for the presence of zero, I don’t know how to do this.
Problem conditions:
For each row of a given 8x5 matrix A,
find and print the numbers of columns containing zero
elements and their number.

Task code:

#include <stdio.h>

int main() {
    int matrix[8][5] = {{4, 5, 1,  0,  4},
                        {1, 8, 0,  2,  3},
                        {8, 5, 1,  -5, 0},
                        {6, 4, -3, 0,  1},
                        {0, 4, 6,  1,  0},
                        {6, 7, 0,  5,  1},
                        {1, 6, 3,  9,  7},
                        {3, 4, 7,  0,  2}};
    int count=0;
    int p=matrix[0][0];
    int jj=0;
    int ii=0;
    int n=0;
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 5; j++) {
            printf("%i\t", matrix[i][j]);
        }
        printf("\n");
    }
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 5; j++) {
            if (matrix[i][j] == 0) {
                n++;
                if (n == ) {
                    p=matrix[i][j];
                    jj=j;
                    ii=i;
                    count++;
                }
            }
        }
    }
    printf("\n[%i][%i]=%i", ii,jj,p);
    printf("\ncount=%d",count);
    return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TriKrista, 2020-11-26
@TriKrista

printf("\n[%i][%i]=%i", ii,jj,p);
This needs to be done in a loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question