![]() |
|
C programmer?? - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: C, C++, & Obj-C (https://sinister.ly/Forum-C-C-Obj-C) +--- Thread: C programmer?? (/Thread-C-programmer) |
C programmer?? - Yusadolat - 06-05-2014 write a program in C to print out the entries along the diagonal of a matrix and the sum. RE: C programmer?? - Ex094 - 06-05-2014 Will we can't code the entire program for you but if you can provide us with the coding you've done maybe we'll be able to give you some headup RE: C programmer?? - alok9shm - 06-05-2014 I can give you the brief idea. I hope you have already generated the following matrix by now[3x3 (m x m) for example]. [table] [row] [cell]a[0][0] [/cell] [cell]a[0][1] [/cell] [cell]a[0][2] [/cell] [/row] [row] [cell]a[1][0] [/cell] [cell]a[1][1] [/cell] [cell]a[1][2] [/cell] [/row] [row] [cell]a[2][0] [/cell] [cell]a[2][1] [/cell] [cell]a[2][2] [/cell] [/row] [/table] i -> row and j -> column The trick: print a[i][j] only when i=j or i+j==m-1 Hope you got it. RE: C programmer?? - Yusadolat - 06-05-2014 hmmm thanks bro i got it RE: C programmer?? - erpicci - 06-05-2014 The solution by @alok9shm is of course correct, but I would add some info just for the sake of correctness. Please note that, in C, the concept of matrix is vacous since the language does not provide such "type". Programmers can build something representing a matrix in different ways; the most common ones are:
See Wikipedia - Vectorization. |