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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Inner reducing pattern printing
- Printing Heart Pattern in C
- Printing Triangle Pattern in Java
- Printing the Triangle Pattern using last term N
- 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 snake pattern
- Find orientation of a pattern in a matrix
- Print matrix in diagonal pattern
- Print matrix in snake pattern from the last column
- Print numbers in matrix diagonal pattern
- Print concentric rectangular pattern in a 2d matrix
- Print lower triangular matrix pattern from given array
- Check if a string follows a^nb^n pattern or not
- Print a String in wave pattern
- Count of occurrences of a "1(0+)1" pattern in a string
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.