![]() |
|
#1
|
|||
|
|||
Array in spiral orderYour program should print the contents of a 2-dimensional array in spiral order. Suppose your array is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 The output should be: 1 2 3 4 5 6 12 18 24 23 22 21 20 19 13 7 8 9 10 11 17 16 15 14 Your program should take m and n as inputs, where m and n specify the dimensions of the array. Once the user inputs m and n, the program should initialize the array with random numbers using the rand() function. Once the array is initialized, print the actual contents of the array. Then, compute and print the array in spiral order. |
|||
|
#2
|
|||
|
|||
Re: Array in spiral orderQuote:
http://www.gidforums.com/showpost.ph...02&postcount=2 |
|
#3
|
|||
|
|||
Re: Array in spiral orderThe way that I would do it is:
|
|
#4
|
||||
|
||||
Re: Array in spiral orderQuote:
Here is a solution that works for square dimensions for your array. I'll leave it to you to decide how to implement m != n dimensioned array spiral printing. You may want to consider fakepoo's "Map" strategy, though. Only twice the storage and processing! CPP / C++ / C Code:
Output: Code:
MxB |
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| where is the problem and can you fix it (php) | oggie | MySQL / PHP Forum | 8 | 14-Apr-2008 16:08 |
| Getting a line error in register | oggie | MySQL / PHP Forum | 5 | 13-Apr-2008 17:16 |
| What is an array? | Howard_L | C Programming Language | 3 | 05-Oct-2007 06:11 |
| How to sort in C++ alphabetically | wilen | C++ Forum | 5 | 20-Apr-2007 15:43 |
| Need help deleting the last element in the array | headphone69 | C++ Forum | 2 | 15-Mar-2006 20:31 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The