So i have a matrix. (n rows, m cols), and my program has to count the number of rows, where all the cols were >0. For eg. there are n cities, and m bird species. The program has to count the number of cities, where all the bird species (m) were found. (where every m is >0)

So far, i have this, but it's totally wrong:

int c=0;
    for(int i=0; i<m; ++i)
    {
        for(int j=0; j<n; ++j)
        if(bird[i][j]>0) c++;
    }
    cout<<c;

Could you please help me with this?

Your inner loop is going to control the columns (it's a bit confusing because people usually specify dimensions as m rows by n columns, but you've done the opposite), so the inner (j loop) should go to m and your outer (i loop) loop should go to n.

So your loop hits the first row (i = 0)
Then goes and hits each of the columns (j = 0,1,2,..,m)
Second row (i = 1)
Then each of the m columns again
Etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.