Program for Expressionless Face Pattern printing

Given the value of n, i.e, number of lines, print the pattern.

Examples :

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

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

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ implementation to print the pattern
#include <bits/stdc++.h>
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;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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. 

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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. 

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP implementation for
// expressionless face pattern
  
function print1($i)
{
    for ($j = 1; $j <= $i; $j++)
        echo "*";
}
  
function printp($n)
{
    for ($i = 1; $i <= $n; $i++) 
    {
  
        // function calling to print
        // the initial stars in each line
        print1($i);
  
        // printing underscore
        echo "_";
  
        // function calling to print
        // stars on right side of first half
        print1($n - $i + 1);
  
        // printing underscore
        echo "_";
  
        // function calling to print
        // stars on left side of second half
        print1($n - $i + 1);
  
        // printing underscore
        echo "_";
  
        // function calling to print
        // the ending stars
        print1($i);
        echo "\n";
    }
}
  
// Driver code
$n = 5;
printp($n);
  
// This code is contributed by Mithun Kumar
?>

chevron_right



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.