Javatpoint Logo
Javatpoint Logo

Concentric Rectangular Pattern in C++

The phrase "concentric" refers to a pattern in which a number of spheres, circles, or other shapes are placed around a central point, with each following shape enclosing the previous one. In order to achieve symmetry and balance around a main axis, components are often placed in a hierarchy of layers or levels, which is what the word most commonly refers to. Concentric shapes are widely seen in nature, the arts, and architecture, and they might stand for balance, completeness, and harmony. This concept has applications in biology, engineering, and architecture, where grouping structures around a core feature can have advantageous functional or aesthetically pleasing consequences.

A concentric rectangular pattern is a design or layout used in computer programming in which a number of rectangles of different sizes are placed around a common center. Graphical user interfaces (GUIs), data visualization, and game design are just a few examples of applications that might benefit from this configuration's aesthetic beauty and organization.

The concept requires positioning or arranging rectangles to produce a collection of nested structures resembling tree rings. The pattern's focal point is the central rectangle, which is flanked by following rectangles that increase in size accordingly. The dimensions, locations, and offsets from the center point of each rectangle were computed to produce this pattern.

There are many ways to implement the pattern. When we have two inputs for rows and columns, another way is to take an input that will print the rows and columns based on the single input, and another way is to print the pattern in such a way that the input digit is the outermost one for the rectangle.

1. The pattern which takes two inputs for rows and columns:

Output:

Concentric Rectangular Pattern in C++

2. Print the pattern, which takes only one input for rows and columns:

Output:

Concentric Rectangular Pattern in C++

3. Printing the pattern in a way that only the input will be the border:

Output:

Concentric Rectangular Pattern in C++

Explanation:

  • To print the above pattern, we need to understand that the matrix has '2n - 1' rows and '2n - 1' columns, and it is split into two halves: the top half has rows from '0 to floor((2n - 1)/2)', while the bottom half has rows from 'floor((2n - 1)/2) + 1' to '2*n - 2'. The pattern for each row is composed of a falling sequence, a constant sequence, and a rising sequence.
  • A sequence of loops and fundamental arithmetic operations are used to alter the numbers printed in each cell to carry out the reasoning. The symmetry of the top and bottom halves, with the exception of the central row, makes the procedure simpler.
  • The top-half approach entails managing the pattern by performing a loop from row 0 to 'floor((2*n - 1)/2)' and computing the numbers in accordance with the stated logic. While the second section employs the constant "n - i", the first and third parts use decreasing and ascending sequences. The result of this is the upper portion of the design.
  • The bottom half solution employs a loop from "floor((2*n - 1)/2)" down to 0 to build the pattern in the lower half and produce a symmetrical and attractive design.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA