The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 3 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
The problem which arises with the usual printing devices is that they print only in serial format. They start printing or displaying text from the left most character and proceed towards right to display a line. Due to this it is difficult to print different formats of data and the design patterns efficiently on screen.
Your task is to print a matrix of order n*n with numbers from 1 to n2 in a spiral format. In this format the entry of numbers start from center of the matrix and the filling is proceeded in the anticlockwise direction. The ending cell for even values of n is the first cell (1, 1) and for the odd values of n is the last cell (n, n) of the matrix.
The input consists of a single number n such that 0
The output consist of an n*n matrix filled in spirally anticlockwise direction.
Input: 4 Output: 16 15 14 13 5 4 3 12 6 1 2 11 7 8 9 10
Input: 5 Output: 17 16 15 14 13 18 5 4 3 12 19 6 1 2 11 20 7 8 9 10 21 22 23 24 25
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll