How to check separate elements in array rows?



I am very new at this and I am kind of a self-learner so don't be so harsh , please. I have a task to write a code for the following: Arr[3][4]={{1.5, 2.1, -3.5, -4.3},{-2.3, 5.2, 6.1, 7.6} ,{-3.3,-4.4,-5.6, 7.2}};

I have to check every element in every row and the row with more positive elements should go on the top and be switched with the first row.

My main problem is that I don't know how to check the elements for every row separately and than compare the rows and switch them.

Up until now I manage to create only a function that checks all of the positive elements in the whole array and just print them in another array in one row, but that's not actually what I need.
Last edited on
So with the input shown above, what is your desired output?

I want all the rows to be checked for positive elements and the one with most to be switched with the first row. Like in this case the second row to be switched with the first one because it has more positive elements than the first and the third one.
I can do a simple swap function, but I don't know how to check every element and compare the rows.
You'll need to iterate through the rows counting the number of positive values, probably using a couple of loops.

Topic archived. No new replies allowed.