473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

problem on arrays plz help its urgent

Hello

Let A be an array of n elements.Procedure which takes this array as i/p
and produce a matrix which shuold be spiral in nature i.i

if A = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]

7 8 9 10
6 1 2 11
5 4 3 12
16 15 14 13

if n is not a full square then dummy elements can be included to make
the o/p matrix complete.

can any one of you help me in how to write the above in C

Thanks In Advance
Poornima

Jan 8 '07 #1
4 1282
Poornima said:

<snip>
can any one of you help me in how to write the above in C
How would you do it on paper?

1. Fully document your method.
2. Examine each step in your method. Is it sufficiently simple that you
could explain it to a computer? If not, split it into two or more simpler
descriptions, and return to Step 2.
3. Translate your description into C.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 8 '07 #2
Poornima wrote:
Hello

Let A be an array of n elements.Procedure which takes this array as i/p
and produce a matrix which shuold be spiral in nature i.i

if A = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]

7 8 9 10
6 1 2 11
5 4 3 12
16 15 14 13

if n is not a full square then dummy elements can be included to make
the o/p matrix complete.

can any one of you help me in how to write the above in C
The real meat of the program would be the algorithm or set of
algorithms that inject the array elements into the matrix in a spiral
fashion. It's not hard to do, but it requires a bit of thinking. As
Richard suggests, it's better to sit down with a pencil and paper and
write the generic, (i.e. independant of any particular syntax), steps
needed to accomplish your task. Once that's done, translating the steps
into C will be fairly straightforward.

I suggest making a first attempt and posting here or in
comp.programming. You'll generally get better responses to an actual
attempt with code than simple pleas for help.

Jan 8 '07 #3
"Poornima" <po*******************@gmail.comwrote in message
news:11*********************@42g2000cwt.googlegrou ps.com...
Hello

Let A be an array of n elements.Procedure which takes this array as i/p
and produce a matrix which shuold be spiral in nature i.i

if A = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]

7 8 9 10
6 1 2 11
5 4 3 12
16 15 14 13

if n is not a full square then dummy elements can be included to make
the o/p matrix complete.

can any one of you help me in how to write the above in C
No, but I can give you a hint as to where to start. Suppose n is a full square.
Matrix size is sqrt(n) by sqrt(n) fields.
Number 1 should be at the position: ((int) sqrt(n)) / 2, ((int) sqrt(n)) / 2
Now, note the pattern in the spiral matrix: to make a spiral, you first move
(inside the matrix) once horizontally to the right, then once vertically down.
After that, you move twice horizontally to the left and twice vertically up.
Then three times horizontally to the right and three times vertically down, etc.
(Get the pattern?)
At each step, you write down the number which is next in the input array.
Now translate this into C by the method given to you by Richard.

--
"It is easy in the world to live after the world's oppinion; it easy in solitude
to live after our own; but the great man is he who in the midst of the crowd
keeps with perfect sweetness the independence of solitude."
Ralph Waldo Emerson, Self-reliance 1841
http://pinpoint.wordpress.com/

Jan 8 '07 #4
"Sourcerer" <en****@MAKNIgmail.comwrote in message
news:en**********@ss408.t-com.hr...
>
Number 1 should be at the position:
Sorry, this should be "The first number in the list should be at the position:"

--
"It is easy in the world to live after the world's oppinion; it easy in solitude
to live after our own; but the great man is he who in the midst of the crowd
keeps with perfect sweetness the independence of solitude."
Ralph Waldo Emerson, Self-reliance 1841
http://pinpoint.wordpress.com/

Jan 8 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rob | last post by:
I have a form - when you click the submit button, it appends a variable to the URL (e.g. xyz.cgi?inputID=some_dynamic_variable) It also opens a new page. Now, that some_dynamic_variable is...
9
by: Stefan Bauer | last post by:
Hi NG, we've got a very urgent problem... :( We are importing data with the LOAD utility. The input DATE field data is in the format DDMMYYYY (for days) and MMYYYY (for months). The target...
28
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
2
by: aka | last post by:
Hi all I have two arrays . array1 contains 10 elements array2 contains 6 elements I need to assign the left over 4 elements of array1 into new array . Can anyone give me a peice of code ,how to...
1
by: tigerved | last post by:
Hi I am new to this so I dont exactly know the format in which to post the questions ....anyways here goes ...my file looks like this Year,Day,MOnth,latitude,longitude (commas included)...
0
by: fariba123 | last post by:
there are two arrays: $players = array( "23" => "Michael Jordan", "32" => "Michael Johnson" ); $current_player = array( "player_id" => "23", "age" => "22"
9
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
1
by: AnduSe23 | last post by:
Hi, I implemented a solution for a homework assignment and everytime i run my program it crashes. could someone tell me what i'm doing wrong? I so confused what to pass into the functions when...
7
by: thegreatest21 | last post by:
Right, I am making a Tax Calculator and need an array to store the data that has been typed in when the user is prompted. However, being completely new to Java I am having some difficulty getting to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.