P
P
Parsifeel2018-12-23 20:43:30
WordPress
Parsifeel, 2018-12-23 20:43:30

How to find the number of positive elements in each row?

Given a 3 by 3 matrix filled with random numbers.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define M 3
#define N 3
int main() {
    int a[N][M], i, j;
    srand(time(NULL));
    for (i=0; i<N; i++) {
        for (j=0; j<M; j++) {
            a[i][j] = rand() % 20 - 10;
            printf("%4d", a[i][j]);
        }
        printf("\n");
    }
}

How to find and output the number of positive elements in each row?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AVKor, 2018-12-23
@AVKor

Loop through each line: create a counter, check each element of the line, if positive, increase the counter by 1. After passing through each line, display the value of the counter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question