new post


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++


[sourcecode language=”CPP”]

// CPP program to print hollow mirrored
// parallelogram star pattern series

#include
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; } [/sourcecode] [tabby title="C"] [sourcecode language="C"] // C program to print hollow mirrored // parallelogram star pattern series #include

// 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; } [/sourcecode] [tabby title ="Java"] [sourcecode language="Java"] // 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); } } [/sourcecode] [tabby title="C#"] [sourcecode language="CSHARP"] // 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 [/sourcecode] [tabbyending]

Output:

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


My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.