📜  无表情面部图案打印程序

📅  最后修改于: 2022-05-13 01:57:58.615000             🧑  作者: Mango

无表情面部图案打印程序

给定 n 的值,即行数,打印模式。
例子 :

Input : n = 5
Output :
*_*****_*****_*
**_****_****_**
***_***_***_***
****_**_**_****
*****_*_*_*****

Input : n = 10
Output :
*_**********_**********_*
**_*********_*********_**
***_********_********_***
****_*******_*******_****
*****_******_******_*****
******_*****_*****_******
*******_****_****_*******
********_***_***_********
*********_**_**_*********
**********_*_*_**********

C++
// C++ implementation to print the pattern
#include 
using namespace std;
 
// Function to print required
// number of stars
void print1(int i)
{
    for (int j = 1; j <= i; j++)
        cout << "*";
}
void print(int n)
{
    for (int i = 1; i <= n; i++) {
 
        // function calling to print
        // the initial stars in each line
        print1(i);
 
        // printing underscore
        cout << "_";
 
        // function calling to print
        // stars on right side of first half
        print1(n - i + 1);
 
        // printing underscore
        cout << "_";
 
        // function calling to print
        // stars on left side of second half
        print1(n - i + 1);
 
        // printing underscore
        cout << "_";
 
        // function calling to print
        // the ending stars
        print1(i);
        cout << endl;
    }
}
 
// Driver code
int main()
{
    // number of lines
    int n = 5;
 
    // function calling
    print(n);
 
    return 0;
}


Java
// Java implementation to print the pattern
import java.io.*;
 
class GFG
{
    // Function to print required
    // number of stars
    static void print1(int i)
    {
        for (int j = 1; j <= i; j++)
            System.out.print("*");
    }
    static void print(int n)
    {
        for (int i = 1; i <= n; i++) {
     
            // function calling to print
            // the initial stars in each line
            print1(i);
     
            // printing underscore
            System.out.print("_");
     
            // function calling to print
            // stars on right side of first half
            print1(n - i + 1);
     
            // printing underscore
            System.out.print("_");
     
            // function calling to print
            // stars on left side of second half
            print1(n - i + 1);
     
            // printing underscore
            System.out.print("_");
     
            // function calling to print
            // the ending stars
            print1(i);
            System.out.println();
        }
    }
     
    // Driver code
    public static void main (String[] args)
    {
        // number of lines
        int n = 5;
     
        // function calling
        print(n);
 
    }
}
 
// This code is contributed by vt_m.


Python3
# Python3 implementation
# to print the pattern
 
# Function to print
# required number of stars
def print1(i):
 
    for j in range(1, i + 1):
        print("*", end = "")
 
def printPattern(n):
 
    for i in range(1, n + 1):
 
        # function calling to
        # print the initial
        # stars in each line
        print1(i)
 
        # printing underscore
        print("_", end = "")
 
        # function calling to
        # print stars on right
        # side of first half
        print1(n - i + 1)
 
        # printing underscore
        print("_", end = "")
 
        # function calling to
        # print stars on left
        # side of second half
        print1(n - i + 1)
 
        # printing underscore
        print("_", end = "")
 
        # function calling to print
        # the ending stars
        print1(i)
        print("")
 
# Driver code
# number of lines
n = 5
 
# function calling
printPattern(n)
 
# This code is contributed
# by Smitha


C#
// C# implementation to print the pattern
using System;
 
class GFG {
     
    // Function to print required
    // number of stars
    static void print1(int i)
    {
        for (int j = 1; j <= i; j++)
            Console.Write("*");
    }
     
    static void print(int n)
    {
        for (int i = 1; i <= n; i++) {
     
            // function calling to print
            // the initial stars in each line
            print1(i);
     
            // printing underscore
            Console.Write("_");
     
            // function calling to print
            // stars on right side of first half
            print1(n - i + 1);
     
            // printing underscore
            Console.Write("_");
     
            // function calling to print
            // stars on left side of second half
            print1(n - i + 1);
     
            // printing underscore
            Console.Write("_");
     
            // function calling to print
            // the ending stars
            print1(i);
            Console.WriteLine();
        }
    }
     
    // Driver code
    public static void Main ()
    {
         
        // number of lines
        int n = 5;
     
        // function calling
        print(n);
    }
}
 
// This code is contributed by vt_m.


PHP


Javascript


输出 :

*_*****_*****_*
**_****_****_**
***_***_***_***
****_**_**_****
*****_*_*_*****