Given a string, print it inside a matrix in such a way that a ‘plus’ is formed.
Input: TOP Output: X T X T O P X P X Input: FEVER Output: X X F X X X X E X X F E V E R X X E X X X X R X X
The idea is simple. First we can access every element of the matrix and make it ‘X’. Then we will insert the characters of the string in the middle row as well as in the middle column of the matrix. For example, we have string of length 5. So we will need a (5X5) matrix for it.
To access the middle column of the matrix, column index is made constant and is equal to (n/2), where n is the length of the string. Row index will go from 0 to (n-1) for it.
To access the middle row, the row index will be made constant and equal to (n/2) and the column index will go from 0 to (n-1).
Below is the implementation of above approach:
X X X P X X X X X X I X X X X X X C X X X P I C T U R E X X X U X X X X X X R X X X X X X E X X X
- Inner reducing pattern printing
- Printing Heart Pattern in C
- Printing the Triangle Pattern using last term N
- Printing Triangle Pattern in Java
- How to learn Pattern printing easily?
- Program for Expressionless Face Pattern printing
- Pattern Printing question asked in CGI Coding Round
- Printing brackets in Matrix Chain Multiplication Problem
- Printing Matrix Chain Multiplication (A Space Optimized Solution)
- Find N in the given matrix that follows a pattern
- Print matrix in diagonal pattern
- Print matrix in snake pattern
- Find orientation of a pattern in a matrix
- Print numbers in matrix diagonal pattern
- Print concentric rectangular pattern in a 2d matrix
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.