Program to Print Mirrored Hollow Parallelogram in C

A mirrored hollow parallelogram is a pattern where a hollow parallelogram shape is printed with leading spaces to create a mirrored or slanted effect. The pattern consists of stars forming the outline while the interior remains hollow.

Syntax

for(r = 1; r <= rows; r++) {
    for(c = 1; c < r; c++) {
        printf(" ");
    }
    for(c = 1; c <= cols; c++) {
        if (r == 1 || r == rows || c == 1 || c == cols) {
            printf("*");
        } else {
            printf(" ");
        }
    }
    printf("<br>");
}

Algorithm

  • Accept the number of rows and columns from the user
  • Run an outer loop for rows: for(r=1; r<=rows; r++)
  • For each row, print leading spaces using: for(c=1; c<r; c++)
  • Print stars for the border and spaces for the hollow interior using the condition: r==1 || r==rows || c==1 || c==cols
  • Move to the next line after completing each row

Example

This program creates a mirrored hollow parallelogram pattern using nested loops −

#include <stdio.h>

int main() {
    int rows, cols, r, c;
    
    printf("Please enter the number of Rows: ");
    scanf("%d", &rows);
    printf("Please enter the number of Columns: ");
    scanf("%d", &cols);
    
    printf("\nThe Mirrored Hollow Parallelogram is:<br>");
    
    for(r = 1; r <= rows; r++) {
        // Print leading spaces
        for(c = 1; c < r; c++) {
            printf(" ");
        }
        
        // Print hollow parallelogram
        for(c = 1; c <= cols; c++) {
            if (r == 1 || r == rows || c == 1 || c == cols) {
                printf("*");
            } else {
                printf(" ");
            }
        }
        printf("<br>");
    }
    
    return 0;
}
Please enter the number of Rows: 5
Please enter the number of Columns: 8
The Mirrored Hollow Parallelogram is:
********
 *      *
  *      *
   *      *
    ********

How It Works

  • Leading Spaces: Each row r prints (r-1) spaces to create the mirrored effect
  • Border Stars: Stars are printed only at the first row, last row, first column, or last column
  • Hollow Interior: All other positions print spaces to create the hollow effect

Conclusion

The mirrored hollow parallelogram pattern uses nested loops with conditional printing to create a slanted hollow shape. The key is controlling the leading spaces and identifying border positions for star placement.

Updated on: 2026-03-15T12:35:53+05:30

750 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements