Program to Print Mirrored Hollow Parallelogram

06 Jun, 2022
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++
C
Java
Python3
C#
PHP
Javascript
// CPP program to print hollow mirrored// parallelogram star pattern series #include <iostream>using namespace std; // function for creating patternvoid 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 codeint main(){    // Get number of rows and columns    int rows = 5, cols = 8;     // Print the Pattern    Pattern(rows, cols);     return 0;}
// C program to print hollow mirrored// parallelogram star pattern series #include <stdio.h> // function for creating patternvoid 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 codeint main(){    // Get number of rows and columns    int rows = 5, cols = 8;     // Print the Pattern    Pattern(rows, cols);     return 0;}
// Java program to print hollow mirrored// parallelogram star pattern seriesimport java.util.*; class solution{ // function for creating patternstatic 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 codepublic static void main(String args[]){    // Get number of rows and columns    int rows = 5, cols = 8;     // Print the Pattern    Pattern(rows, cols);     } }
# Python3 program to prhollow mirrored# parallelogram star pattern seriesimport math as mt # function for creating patterndef 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 columnsrows, cols = 5, 8 # Print the PatternPattern(rows, cols) # This code is contributed by# mohit kumar 29
// C# program to print hollow mirrored// parallelogram star pattern seriesusing System; class GFG{ // function for creating patternstatic 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 codepublic 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
<?php// PHP program to print hollow mirrored// parallelogram star pattern series // function for creating patternfunction Pattern($rows, $cols){    for ($i = 1; $i <= $rows; $i++)    {         // Printing spaces        for ($j = 1; $j < $i; $j++)        {            echo " ";        }         // Printing hollow parallelogram        for ($j = 1; $j <= $cols; $j++)        {             if ($i == 1 || $i == $rows||                $j == 1 || $j == $cols)            {                echo "*";            }            else            {                echo " ";            }        }         echo "\n";    }} // Driver Code // Get number of rows and columns$rows = 5; $cols = 8; // Print the PatternPattern($rows, $cols); // This code is contributed by// Akanksha Rai?>
<script>       // JavaScript program to print hollow mirrored      // parallelogram star pattern series       // function for creating pattern      function Pattern(rows, cols) {        var i, j;         for (i = 1; i <= rows; i++) {          // Printing spaces          for (j = 1; j < i; j++) {            document.write("  ");          }           // Printing hollow parallelogram          for (j = 1; j <= cols; j++) {            if (i == 1 || i == rows || j == 1 || j == cols) {              document.write("*");            } else {              document.write("  ");            }          }           document.write("<br>");        }      }       // driver code      // Get number of rows and columns      var rows = 5,        cols = 8;       // Print the Pattern      Pattern(rows, cols);       </script>
********
 *      *
  *      *
   *      *
    ********
 
Time Complexity: O(rows * cols), where n represents the given number of rows and columns.Auxiliary Space: O(1), no extra space is required, so it is a constant.
SURENDRA_GANGWAR
Rajput-Ji
mohit kumar 29
Akanksha_Rai
nidhi_biet
rdtank
tamanna17122007
pattern-printing
school-programming
C Language
C++
pattern-printing
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Functions that cannot be overloaded in C++
Switch Statement in C/C++
Substring in C++
Left Shift and Right Shift Operators in C/C++
std::string class in C++
C++ Classes and Objects
Vector in C++ STL
Object Oriented Programming in C++
Writing First C++ Program - Hello World Example
Inheritance in C++