https://github.com/ammara-masood06/c_plus_plus_hourglass_pattern
C++ Hourglass Pattern Generator ⏳ Builds a dynamic, user-defined pattern using nested loops. Perfect for demonstrating fundamental C++ control flow and I/O mastery.
https://github.com/ammara-masood06/c_plus_plus_hourglass_pattern
cplusplus forloop hourglasspattern nested-for-loops nested-loops patterns
Last synced: 4 days ago
JSON representation
C++ Hourglass Pattern Generator ⏳ Builds a dynamic, user-defined pattern using nested loops. Perfect for demonstrating fundamental C++ control flow and I/O mastery.
- Host: GitHub
- URL: https://github.com/ammara-masood06/c_plus_plus_hourglass_pattern
- Owner: Ammara-Masood06
- Created: 2025-11-11T17:13:51.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-11-11T17:20:21.000Z (7 months ago)
- Last Synced: 2025-12-26T08:58:40.084Z (5 months ago)
- Topics: cplusplus, forloop, hourglasspattern, nested-for-loops, nested-loops, patterns
- Language: C++
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
**Dynamic Hourglass Pattern Generator in C++**
This C++ console application creates a visual hourglass pattern of customizable size based on user input. It is an excellent demonstration of nested loop management and foundational C++ programming logic.
**⚙️ How It Works**
The pattern is constructed by printing characters (^) and strategic spacing in two distinct phases:
**1. Upper Half: The Inverted Pyramid**
This section is responsible for the top half of the hourglass, where the pattern starts wide and narrows to the center.
**Outer Loop (i):** Iterates from the first row (1) up to the user-specified row count (r).
**Space Loop (j):** Prints the leading spaces before the characters. The number of spaces increases with each row (i), which pushes the pattern inward, creating the indentation.
**Character Loops (k and l):** These loops are used to print the ^ characters. As the row number (i) increases, the number of characters printed decreases, causing the pattern to taper towards the center.
**Output:** Each iteration ends with cout << endl; to move to the next row.
**2. Lower Half:** The Regular Pyramid
This section completes the hourglass by mirroring the top half, starting from the narrowest point and widening back out.
**Outer Loop (i):** Iterates from the widest row back up to 1 (r down to 1) to control the size progression.
**Space Loop (j):** Prints leading spaces. The number of spaces decreases as the pattern widens, pulling the characters back towards the margins.
**Character Loops (k and l):** As the loop progresses, the total number of characters printed increases, causing the pattern to widen back out and complete the visual hourglass shape.