Write in a programming language (PL), a program to fill an NxN two- dimensional array, in a circular (spiral) pattern, with numbers from 1 to N2 as described below. You can do that by writing first the following functions/procedures which you will call in the main program. The procedure FillColumnUpward(A, top, bottom, left, z) which takes the array A the top, bottom and left as parameters and iterates through the left column from bottom to top to fill the column.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 17RQ
icon
Related questions
Question

Write in a programming language (PL), a program to fill an NxN two- dimensional array, in a circular (spiral) pattern, with numbers from 1 to N2 as described below. You can do that by writing first the following functions/procedures which you will call in the main program.

  • The procedure FillColumnUpward(A, top, bottom, left, z) which takes the array A the top, bottom and left as parameters and iterates through the left column from bottom to top to fill the column. 
2. There are many different ways of placing the numbers 1 to N'into an N x N two dimensional array.
The following two-dimensional array, with dimensions 5x5, has been filled in a circular
(spiral) pattern with numbers I to 5
An algorithm to fill an NxN two-dimensional array, in a circular (spiral) pattern,
with numbers from I to N' is given as follows:
• initialize Z-1,
•initialize TOP, BOTTOM, LEFT and RIGIHT.
• iterate until the whole array is filled.
• cach time Z is placed correctly increase the value of Z by 1.
• fill the elements of the TOP row starting from LEFT to RIGHT.
• increase TOP by I before filling the clements of the RIGHT column.
• fill the clements of the RIGHT column starting from TOP to BOTTOM.
• decrease RIGHT by I before filling the clements of the BOTTOM row.
• and continue filling the BOTTOM row and LEFT column in a similar way.
adjusting TOP, RIGHT, BOTTOM and LEFT accordingly.
LEFT
RIGHT
[0]
(1]
[2]
[3]
[4]
TOP
(0]
1
4
[1]
16
17
19
6.
[2]
15 24
25
7
[3]
14
23
22
8
[4]
13
12
11
10
BOTTOM
Figure 2
20
21
18
2.
Transcribed Image Text:2. There are many different ways of placing the numbers 1 to N'into an N x N two dimensional array. The following two-dimensional array, with dimensions 5x5, has been filled in a circular (spiral) pattern with numbers I to 5 An algorithm to fill an NxN two-dimensional array, in a circular (spiral) pattern, with numbers from I to N' is given as follows: • initialize Z-1, •initialize TOP, BOTTOM, LEFT and RIGIHT. • iterate until the whole array is filled. • cach time Z is placed correctly increase the value of Z by 1. • fill the elements of the TOP row starting from LEFT to RIGHT. • increase TOP by I before filling the clements of the RIGHT column. • fill the clements of the RIGHT column starting from TOP to BOTTOM. • decrease RIGHT by I before filling the clements of the BOTTOM row. • and continue filling the BOTTOM row and LEFT column in a similar way. adjusting TOP, RIGHT, BOTTOM and LEFT accordingly. LEFT RIGHT [0] (1] [2] [3] [4] TOP (0] 1 4 [1] 16 17 19 6. [2] 15 24 25 7 [3] 14 23 22 8 [4] 13 12 11 10 BOTTOM Figure 2 20 21 18 2.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage