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++
// 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
filter_none
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. |
chevron_right
filter_none
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 |
chevron_right
filter_none
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. |
chevron_right
filter_none
PHP
<?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
filter_none
Output :
*_*****_*****_* **_****_****_** ***_***_***_*** ****_**_**_**** *****_*_*_*****
Recommended Posts:
- Inner reducing pattern printing
- Printing Heart Pattern in C
- Printing string in plus ‘+’ pattern in the matrix
- Printing Triangle Pattern in Java
- Printing the Triangle Pattern using last term N
- How to learn Pattern printing easily?
- Pattern Printing question asked in CGI Coding Round
- Program to print the pattern 'G'
- Program for Hexagonal Pattern
- Program to print the given Z Pattern
- Program to print the pattern "GFG"
- Program to print pattern
- Program to print the given H Pattern
- Program to print the pattern ‘D’
- Program to print the Ladder Pattern
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.



