Printing string in plus ‘ + ’ pattern in the matrix | C # program to print the string in ' plus ' pattern ; Function to make a cross in the matrix ; As , it is not possible to make the cross exactly in the middle of the matrix with an even length string . ; declaring a 2D array i . e a matrix ; Now , we will fill all the elements of the array with ' X ' ; Now , we will place the characters of the string in the matrix , such that a cross is formed in it . ; here the characters of the string will be added in the middle column of our array . ; here the characters of the string will be added in the middle row of our array . ; Now finally , we will print the array ; Driver code
using System ; class GFG { static int max = 100 ; static void carveCross ( String str ) { int n = str . Length ; if ( n % 2 == 0 ) { Console . Write ( " Not ▁ possible . ▁ Please ▁ enter ▁ " + " odd ▁ length ▁ string . " ) ; } else { char [ , ] arr = new char [ max , max ] ; int m = n / 2 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { arr [ i , j ] = ' X ' ; } } for ( int i = 0 ; i < n ; i ++ ) { arr [ i , m ] = str [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { arr [ m , i ] = str [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { Console . Write ( arr [ i , j ] + " ▁ " ) ; } Console . WriteLine ( ) ; } } } public static void Main ( ) { string str = " PICTURE " ; carveCross ( str ) ; } }