📜  程序打印镜像空心平行四边形

📅  最后修改于: 2021-05-26 00:47:37             🧑  作者: Mango

给定长度(行)和宽度(列),任务是打印镜像的空心平行四边形。
例子:

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

C++
// 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;
}


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;
}


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);
     
}
 
}


Python3
# 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
 
# Print the Pattern
Pattern(rows, cols)
 
# This code is contributed by
# mohit kumar 29


C#
// 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


PHP


Javascript


输出:
********
 *      *
  *      *
   *      *
    ********
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”