# Program to print number pattern

We have to print a pattern where in middle column contains only 1, right side columns contains constant digit which is greater than 1 and left side columns contains constant digit which is greater than 1. Every row should look like a Palindrome.

Examples :

```Input : 3
Output :
1
2  1  2
1

Input : 5
Output :
1
2  1  2
3 2  1  2 3
2  1  2
1
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Below is the implementation to print following pattern :

## C++

 `// CPP program to print pattern ` `#include ` `using` `namespace` `std; ` ` `  `void` `display() ` `{ ` `     `  `    ``int` `n = 5; ` `    ``int` `space = n / 2, num = 1; ` `      `  `    ``// Outer for loop for  ` `    ``// number of rows ` `    ``for` `(``int` `i = 1; i <= n; i++) ` `    ``{ ` `        ``// Inner for loop for  ` `        ``// printing space ` `        ``for` `(``int` `j = 1; j <= space; j++)             ` `            ``cout<<``" "``; ` `          `  `        ``// Logic for printing  ` `        ``// the pattern for everyline ` `        ``int` `count = num / 2 + 1; ` `         `  `        ``for` `(``int` `k = 1; k <= num; k++) ` `        ``{ ` `            ``cout<

## Java

 `// Java program to print above pattern ` `import` `java.util.Scanner; ` `class` `Pattern ` `{ ` `    ``void` `display() ` `    ``{ ` `        ``int` `n = ``5``; ` `        ``int` `space = n / ``2``, num = ``1``; ` `         `  `        ``// Outer for loop for  ` `        ``// number of rows ` `        ``for` `(``int` `i = ``1``; i <= n; i++) ` `        ``{ ` `            ``// Inner for loop  ` `            ``// for printing space ` `            ``for` `(``int` `j = ``1``; j <= space; j++)             ` `                ``System.out.print(``" "``); ` `             `  `            ``// Logic for printing  ` `            ``// the pattern for everyline ` `            ``int` `count = num / ``2` `+ ``1``; ` `            ``for` `(``int` `k = ``1``; k <= num; k++) ` `            ``{ ` `                ``System.out.print(count); ` `                ``// Value of count decrements  ` `                ``// in every cycle  ` `                ``if` `(k <= num /``2` `) ` `                    ``count--; ` ` `  `                ``// Value of count will increment  ` `                ``// in every cycle ` `                ``else` `                    ``count++; ` `            ``} ` ` `  `            ``System.out.println(); ` ` `  `            ``// Befor reaching half Space is decreased ` `            ``// by 1 and num is increased by 2 ` `            ``if` `(i <= n / ``2``) ` `            ``{ ` `                ``space = space - ``1``; ` `                ``num = num + ``2``; ` `            ``} ` ` `  `            ``// After reaching to half space is increased ` `            ``// by 1 and num is decreased by 2 ` `            ``else` `            ``{ ` `                ``space = space + ``1``; ` `                ``num = num - ``2``; ` `            ``} ` `        ``} ` `    ``} ` ` `  `    ``// Driver Code ` `    ``public` `static` `void` `main(String[] args) ` `    ``{ ` `        ``Pattern p = ``new` `Pattern(); ` `        ``p.display(); ` `    ``} ` `} `

## Python3

 `# Python 3 program to  ` `# print above pattern ` ` `  `def` `display() : ` `    ``n ``=` `5` `    ``space ``=` `n ``/``/` `2` `    ``num ``=` `1` `     `  `    ``# Outer for loop for  ` `    ``# number of rows ` `    ``for` `i ``in` `range``(``1``, n``+``1``) : ` `         `  `        ``# Inner for loop for   ` `        ``# printing space ` `        ``for` `j ``in` `range``(``1``, space``+``1``) : ` `            ``print``(``" "``, end ``=` `"")  ` `             `  `        ``# Logic for printing the ` `        ``# pattern for everyline ` `        ``count ``=` `num ``/``/` `2` `+` `1` `         `  `        ``for` `k ``in` `range``(``1``, num``+``1``) : ` `            ``print``(count, end ``=` `"") ` `             `  `            ``# Value of count decrements ` `            ``# in every cycle ` `            ``if` `(k <``=` `num ``/``/` `2` `) : ` `                ``count ``=` `count ``-``1` ` `  `            ``# Value of count will  ` `            ``# increment in every cycle ` `            ``else` `: ` `                ``count ``=` `count ``+` `1` `        ``print``() ` ` `  `        ``# Befor reaching half Space ` `        ``# is decreased by 1 and num ` `        ``# is increased by 2 ` `        ``if` `(i <``=` `n ``/``/` `2``) : ` `            ``space ``=` `space ``-` `1` `            ``num ``=` `num ``+` `2` `         `  `        ``# After reaching to half  ` `        ``# space is increased by 1 ` `        ``# and num is decreased by 2 ` `        ``else` `: ` `            ``space ``=` `space ``+` `1` `            ``num ``=` `num ``-` `2` `             `  `# Driver Code ` `display() ` ` `  `#This code is contributed by Nikita Tiwari. `

## C#

 `// C# program to print above pattern ` `using System; ` `class Pattern ` `{ ` `    ``void display() ` `    ``{ ` `        ``int n = 5; ` `        ``int space = n / 2, num = 1; ` `         `  `        ``// Outer for loop for  ` `        ``// number of rows ` `        ``for (int i = 1; i <= n; i++) ` `        ``{ ` `            ``// Inner for loop  ` `            ``// for printing space ` `            ``for (int j = 1; j <= space; j++)          ` `                ``Console.Write(" "); ` `             `  `            ``// Logic for printing  ` `            ``// the pattern for everyline ` `            ``int count = num / 2 + 1; ` `            ``for (int k = 1; k <= num; k++) ` `            ``{ ` `                ``Console.Write(count); ` `                ``// Value of count decrements  ` `                ``// in every cycle  ` `                ``if (k <= num /2 ) ` `                    ``count--; ` ` `  `                ``// Value of count will increment  ` `                ``// in every cycle ` `                ``else ` `                    ``count++; ` `            ``} ` ` `  `            ``Console.WriteLine(); ` ` `  `            ``// Befor reaching half Space is decreased ` `            ``// by 1 and num is increased by 2 ` `            ``if (i <= n / 2) ` `            ``{ ` `                ``space = space - 1; ` `                ``num = num + 2; ` `            ``} ` ` `  `            ``// After reaching to half space is increased ` `            ``// by 1 and num is decreased by 2 ` `            ``else ` `            ``{ ` `                ``space = space + 1; ` `                ``num = num - 2; ` `            ``} ` `        ``} ` `    ``} ` ` `  `    ``// Driver Code ` `    ``public static void Main() ` `    ``{ ` `        ``Pattern p = new Pattern(); ` `        ``p.display(); ` `    ``} ` `} ` `// This code is contributed by vt_m. `

## PHP

 ` `

Output :

```  1
212
32123
212
1
```

My Personal Notes arrow_drop_up Hello everyone, I am Bishal KUMAR Dubey and most importantly an idea creator I just love Programming languages and love to know new concepts everyday,every minute,every second Here to help Other GEEKS

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.

Improved By : Mithun Kumar