chaitanya1 Posted February 4, 2010 Report Share Posted February 4, 2010 (edited) how to build a 2d array in spiral manner. example:entered value would be 5,then result should be... a matrix of 5x5 21 22 23 24 25 20 07 08 09 10 19 06 01 02 11 18 05 04 03 12 17 16 15 14 13 Edited February 4, 2010 by chaitanya1 Quote Link to comment
Tim_S Posted February 4, 2010 Report Share Posted February 4, 2010 It's not clear where the values in your array are coming from or are generated. However it sounds like you are looking for the initialize array primative. Tim Quote Link to comment
Gary Rubin Posted February 4, 2010 Report Share Posted February 4, 2010 It's not clear where the values in your array are coming from or are generated. However it sounds like you are looking for the initialize array primative. It appears to me to be a homework assignment related to reshaping/reindexing array values. Values seem to run from 1 to n^2, and are arranged in a particular order such that they spiral outward. Quote Link to comment
chaitanya1 Posted February 13, 2010 Author Report Share Posted February 13, 2010 It appears to me to be a homework assignment related to reshaping/reindexing array values. Values seem to run from 1 to n^2, and are arranged in a particular order such that they spiral outward. yes the values has to get generated as specified.give me solution....... Quote Link to comment
Christian_L Posted February 13, 2010 Report Share Posted February 13, 2010 yes the values has to get generated as specified.give me solution....... give me solution....... ??? Not even a simple please? What have you tried so far? Can you show us your work to date on this problem. What is the application that you are working on where this is important? Quote Link to comment
Grampa_of_Oliva_n_Eden Posted February 15, 2010 Report Share Posted February 15, 2010 yes the values has to get generated as specified.give me solution....... You can give yourself the solution after a little hard work. Sit down and start filling those arrays by hand. As yo do so, start watching for patterns that you follow as you go. WHt you will find is there is a finite set of rules you have to follow to fill the array. After doing it manually a couple of times, right down a set of rules that describe how you decided to put what value where. The rules and procedure you come up with will then drive the nature of your code. Your rules and proceedures should answer question like... Where do I start? When do I continue working in a row or collumn? What does the maiximum and minimum indexes have to do with when I switch from rows to collumns? Once you have it written down such that you can pass the procedure off to a gifted asssistant, then start teh translation in code. For the most part we will not do your home-work for you, but we are willing to help those who want to learn. Ben Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.