Click here to Skip to main content
15,905,915 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: ╠ How get video card memory size ? ╣ Pin
kilt17-Aug-09 3:06
kilt17-Aug-09 3:06 
AnswerRe: ╠ How get video card memory size ? ╣ Pin
bzsolt9123-Aug-09 4:29
bzsolt9123-Aug-09 4:29 
QuestionHow to cause a CPropertySheet to show a particular page .. [SOLVED] Pin
Ahmed Charfeddine16-Aug-09 1:12
Ahmed Charfeddine16-Aug-09 1:12 
AnswerRe: How to cause a CPropertySheet to show a particular page .. Pin
David Crow16-Aug-09 11:31
David Crow16-Aug-09 11:31 
GeneralRe: How to cause a CPropertySheet to show a particular page .. Pin
Ahmed Charfeddine16-Aug-09 11:41
Ahmed Charfeddine16-Aug-09 11:41 
QuestionError 1008 while using CoCreateInstance Pin
emmmatty115-Aug-09 21:19
emmmatty115-Aug-09 21:19 
QuestionPrint and Print Preview and relation with document view Pin
Amin.Abdi15-Aug-09 19:34
Amin.Abdi15-Aug-09 19:34 
AnswerRe: Print and Print Preview and relation with document view Pin
«_Superman_»16-Aug-09 19:06
professional«_Superman_»16-Aug-09 19:06 
QuestionMouse as an erasing tool Pin
kudlaty7915-Aug-09 10:06
kudlaty7915-Aug-09 10:06 
AnswerRe: Mouse as an erasing tool Pin
Michael Schubert15-Aug-09 13:22
Michael Schubert15-Aug-09 13:22 
AnswerRe: Mouse as an erasing tool Pin
«_Superman_»15-Aug-09 17:41
professional«_Superman_»15-Aug-09 17:41 
GeneralRe: Mouse as an erasing tool Pin
kudlaty7916-Aug-09 3:08
kudlaty7916-Aug-09 3:08 
GeneralRe: Mouse as an erasing tool Pin
Cedric Moonen16-Aug-09 20:13
Cedric Moonen16-Aug-09 20:13 
GeneralRe: Mouse as an erasing tool Pin
kudlaty7916-Aug-09 23:01
kudlaty7916-Aug-09 23:01 
GeneralRe: Mouse as an erasing tool Pin
Cedric Moonen16-Aug-09 23:14
Cedric Moonen16-Aug-09 23:14 
QuestionHow to double click desktop icon programatically? Pin
birajendu15-Aug-09 9:15
birajendu15-Aug-09 9:15 
QuestionRe: How to double click desktop icon programatically? Pin
David Crow15-Aug-09 10:40
David Crow15-Aug-09 10:40 
AnswerRe: How to double click desktop icon programatically? Pin
Stuart Dootson15-Aug-09 13:28
professionalStuart Dootson15-Aug-09 13:28 
GeneralRe: How to double click desktop icon programatically? Pin
birajendu15-Aug-09 18:35
birajendu15-Aug-09 18:35 
AnswerRe: How to double click desktop icon programatically? Pin
Graham Shanks15-Aug-09 23:04
Graham Shanks15-Aug-09 23:04 
QuestionHow to print an a 4x4 array in clockwise direction Pin
sharp_k15-Aug-09 8:59
sharp_k15-Aug-09 8:59 
AnswerRe: How to print an a 4x4 array in clockwise direction Pin
Chris Losinger15-Aug-09 9:36
professionalChris Losinger15-Aug-09 9:36 
AnswerRe: How to print an a 4x4 array in clockwise direction Pin
Moreno Airoldi15-Aug-09 9:59
Moreno Airoldi15-Aug-09 9:59 
GeneralRe: How to print an a 4x4 array in clockwise direction Pin
sharp_k15-Aug-09 21:14
sharp_k15-Aug-09 21:14 
GeneralRe: How to print an a 4x4 array in clockwise direction Pin
Moreno Airoldi15-Aug-09 22:54
Moreno Airoldi15-Aug-09 22:54 
Happy to be of help. Smile | :)

About rotating the matrix, it would take more time and more space, so I think it's not a good solution.

Yeah I know that my code wasn't that readable, C pointer math can be hellish...
It works by using a single iterator on rows r. This iterator goes from the first row (0) to the middle row ((rows/2)-1).

First I print the row pointed by r:

C
for (i=r; i<(columns - r); i++) printf("%d ",array[(r*columns)+i]);


then I proceed printing the rightmost column, starting from the last item I printed for row r:

C
for (i=r+2; i<=(rows-r); i++) printf("%d ",array[(i*columns)-1-r]);


I continue with the lowest row, which is printed right to left:

C
for (i=(columns-r-2); i>=r; i--) printf("%d ",array[((rows-r-1)*columns)+i]);


and finally with the first column, bottom to top:

C
for (i=rows-r-2; i>r; i--) printf("%d ",array[(i*columns)+r]);


With each iteration r grows by one. You will see that it's used in all the for loops, in order to move them towards the centre of the matrix one row and one column each.

Hope it's more clear now, if you think it would help I can rewrite this using distinct row and column indexes on the array, in order to make it clearer.

2+2=5 for very large amounts of 2
(always loved that one hehe!)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.