reset password
Author Message
jzunig20
Posts: 38
Posted 21:58 May 06, 2017 |

i've been able to find all the calculations for rows columns average, major diagonals for nxn arrays and nxm arrays but i cant get the minor diagonals going

any pointers for the minor diagonals? 

must we use nested for loops? i think i can figure out how to get the minor diagonals if i use just one for loop to change rows and columns at the same time.

any ideas? 

Arnav98
Posts: 48
Posted 22:26 May 06, 2017 |

I solved that part without using nested loops. I divided that part into 3 cases ( number of rows = number of col, row > col and col > rows). I think this might help you solve the problem.

LuisG72
Posts: 36
Posted 04:29 May 07, 2017 |

The major diagonal is basically matrix[row] [row]  where row = 0 and you increase row every loop, this only works when columns >= rows, if there is more rows than colums then you use matrix[column] [column] and apply the same logic as before. Having said that the minor diagonal is basically a major diagonal that starts at the end and works its way down instead of starting at 0 and working its way up like a major diagonal does. 

jzunig20
Posts: 38
Posted 09:27 May 07, 2017 |
LuisG72 wrote:

The major diagonal is basically matrix[row] [row]  where row = 0 and you increase row every loop, this only works when columns >= rows, if there is more rows than colums then you use matrix[column] [column] and apply the same logic as before. Having said that the minor diagonal is basically a major diagonal that starts at the end and works its way down instead of starting at 0 and working its way up like a major diagonal does. 

Yes thats how i ended up doing it thank you !

kknaur
Posts: 540
Posted 09:47 May 07, 2017 |

FYI You can solve major and minor diagonal using only one loop with two control variables.

jzunig20
Posts: 38
Posted 09:49 May 07, 2017 |

Perfect! its so much easier to have control of both variables in one for loop for diagonals