Hey guys,I'm new,but I study C programming language and I have this awfull problem.
I have make a matrix A[n][n],in which n is an odd positive number(of course),and the matrix must "unwrap" itself with the number 1 in the middle then 2 to the top,then clockwise 3,4,5,..etc,until it wraps the numbers 1 and finishes with the n*n number at the upper left corner...
I've seen the algorithm for the spiral matrix which wraps itself from the outside in,mine is the absolute opposite...I need help fast on this one,if anyone has suggestions I would be very thankful!
Only C,haven't started C++ yet.
=Landoro=
Landoro
0
Newbie Poster
Recommended Answers
Jump to PostAssuming a square NxNmatrix where N is an odd number, it looks like:
Find the center (x,y) where x and y equal N/2 rounded down. Or N>>1;
Go Up One.
Go Right One.
Go Down Two.
Go Left Two.
Go Up Three.
Go Right Three.
...
Happy coding.
Jump to PostConcrats! Now that you have logic right, why not practise some commenting and/or changing the variable names descriptive?
Maybe also you could find little better indention standard as I find for example indention of the for loop lines 22-56 kind of "interesting" ;)
All 5 Replies
DeanMSands3
69
Junior Poster
Landoro
0
Newbie Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
Bchandaria
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.