top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How to print spiral number patterns using only loops, conditions and basic maths?

+10 votes
667 views

Can you print spiral number patterns using only loops (for/while), conditions (if/else) and basic maths? i.e. *without the use of libraries/data structures/arrays*

sample input :4
sample output:

1    2   3  4
12  13  14  5
11  16  15  6
10   9   8  7
posted Jan 28, 2014 by Asmita Agrawal

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

Similar Questions
+3 votes

Given a binary tree print it in inward spiral order i.e first print level 1, then level n, then level 2, then n-1 and so on.

For Ex -

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

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

+1 vote

C: Print the elements of a matrix in anti spiral order?

Input Matrix

1 2 3 
4 5 6 
7 8 9 

Output

5 6 9 8 7 4 1 2 3
+1 vote

For Example:
the prime divisors of 450 are 4,5,3,3,2.

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...