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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find the maximum sum of Plus shape pattern in a 2-D array
- Count of palindromic plus paths in a given Matrix
- Printing Heart Pattern in C
- Pattern Printing question asked in CGI Coding Round
- Inner reducing pattern printing
- Program for Expressionless Face Pattern printing
- Printing Triangle Pattern in Java
- How to learn Pattern printing easily?
- Printing the Triangle Pattern using last term N
- Printing triangle star pattern using a single loop
- Printing brackets in Matrix Chain Multiplication Problem
- Printing Longest Common Subsequence
- Object Oriented Programming in Python | Set 2 (Data Hiding and Object Printing)
- Programs for printing pyramid patterns in Python
- Programs for printing pyramid patterns in C++
- Programs for printing pyramid patterns in Java
- Printing all solutions in N-Queen Problem
- Programs for printing pyramid patterns using recursion
- PHP programs for printing pyramid patterns
- Find orientation of a pattern in a 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.