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 FillRowForward(A, top, left, right, z) which takes the array A the top, left and right as parameters and iterates through top row from left to right to fill the row. z is as used in the algorithm.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 24PE
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 FillRowForward(A, top, left, right, z) which takes the array A the top, left and right as parameters and iterates through top row from left to right to fill the row. z is as used in the algorithm.
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
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning