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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education