Program to Print Mirrored Hollow Parallelogram

Given the length as rows and breadth as cols, the task is to print the mirrored hollow parallelogram.

Examples:

Input: rows = 5, cols = 8
Output:
********
 *      *
  *      *
   *      *
    ********

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to print hollow mirrored
// parallelogram star pattern series
  
#include <iostream>
using namespace std;
  
// function for creating pattern
void Pattern(int rows, int cols)
{
    int i, j;
  
    for (i = 1; i <= rows; i++) {
  
        // Printing spaces
        for (j = 1; j < i; j++) {
            cout << " ";
        }
  
        // Printing hollow parallelogram
        for (j = 1; j <= cols; j++) {
  
            if (i == 1 || i == rows
                || j == 1 || j == cols) {
                cout << "*";
            }
            else {
                cout << " ";
            }
        }
  
        cout << "\n";
    }
}
  
// driver code
int main()
{
    // Get number of rows and columns
    int rows = 5, cols = 8;
  
    // Print the Pattern
    Pattern(rows, cols);
  
    return 0;
}

chevron_right


C

filter_none

edit
close

play_arrow

link
brightness_4
code

// C program to print hollow mirrored
// parallelogram star pattern series
  
#include <stdio.h>
  
// function for creating pattern
void Pattern(int rows, int cols)
{
    int i, j;
  
    for (i = 1; i <= rows; i++) {
  
        // Printing spaces
        for (j = 1; j < i; j++) {
            printf(" ");
        }
  
        // Printing hollow parallelogram
        for (j = 1; j <= cols; j++) {
  
            if (i == 1 || i == rows
                || j == 1 || j == cols) {
                printf("*");
            }
            else {
                printf(" ");
            }
        }
  
        printf("\n");
    }
}
  
// driver code
int main()
{
    // Get number of rows and columns
    int rows = 5, cols = 8;
  
    // Print the Pattern
    Pattern(rows, cols);
  
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to print hollow mirrored
// parallelogram star pattern series
import java.util.*;
  
class solution
{
  
// function for creating pattern
static void Pattern(int rows, int cols)
{
    int i, j;
  
    for (i = 1; i <= rows; i++) {
  
        // Printing spaces
        for (j = 1; j < i; j++) {
            System.out.print(" ");
        }
  
        // Printing hollow parallelogram
        for (j = 1; j <= cols; j++) {
  
            if (i == 1 || i == rows
                || j == 1 || j == cols) {
                 System.out.print("*");
            }
            else {
             System.out.print(" ");
            }
        }
  
         System.out.print("\n");
    }
}
  
// driver code
public static void main(String args[])
{
    // Get number of rows and columns
    int rows = 5, cols = 8;
  
    // Print the Pattern
    Pattern(rows, cols);
      
}
  
}

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to prhollow mirrored
# parallelogram star pattern series
import math as mt
  
# function for creating pattern
def Pattern(rows, cols):
  
    for i in range(1, rows + 1):
          
        # Printing spaces
        for j in range(1, i):
            print(end = " ")
          
        # Printing hollow parallelogram
        for j in range(1, cols + 1):
  
            if (i == 1 or i == rows or
                j == 1 or j == cols):
                print("*", end = "")
            else:
                print(end = " ")
          
        print()
  
# Driver code
  
# Get number of rows and columns
rows, cols = 5, 8
  
# Prthe Pattern
Pattern(rows, cols)
  
# This code is contributed by 
# mohit kumar 29

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to print hollow mirrored
// parallelogram star pattern series
using System;
  
class GFG
{
  
// function for creating pattern
static void Pattern(int rows, int cols)
{
    int i, j;
  
    for (i = 1; i <= rows; i++) 
    {
  
        // Printing spaces
        for (j = 1; j < i; j++) 
        {
            Console.Write(" ");
        }
  
        // Printing hollow parallelogram
        for (j = 1; j <= cols; j++) 
        {
  
            if (i == 1 || i == rows
                || j == 1 || j == cols)
            {
                Console.Write("*");
            }
            else 
            {
                Console.Write(" ");
            }
        }
  
        Console.Write("\n");
    }
}
  
// Driver code
public static void Main()
{
    // Get number of rows and columns
    int rows = 5, cols = 8;
  
    // Print the Pattern
    Pattern(rows, cols);
}
}
  
// This code is contributed by RAJPUT-JI

chevron_right


PHP

Output:

********
 *      *
  *      *
   *      *
    ********


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.