Print Concatenation of Zig | C # program to print string obtained by concatenation of different rows of Zig - Zag fashion ; Prints concatenation of all rows of str 's  Zig-Zag fashion ; Corner Case ( Only one row ) ; Find length of string ; Create an array of strings for all n rows ; Initialize index for array of strings arr [ ] ; True if we are moving down in rows , else false ; Traverse through given string ; append current character to current row ; If last row is reached , change direction to ' up ' ; If 1 st row is reached , change direction to ' down ' ; If direction is down , increment , else decrement ; Print concatenation of all rows ; Driver Code
using System ; class GFG { static void printZigZagConcat ( string str , int n ) { if ( n == 1 ) { Console . Write ( str ) ; return ; } char [ ] str1 = str . ToCharArray ( ) ; int len = str . Length ; string [ ] arr = new string [ n ] ; int row = 0 ; bool down = true ; for ( int i = 0 ; i < len ; ++ i ) { arr [ row ] += ( str1 [ i ] ) ; if ( row == n - 1 ) down = false ; else if ( row == 0 ) down = true ; if ( down ) row ++ ; else row -- ; } for ( int i = 0 ; i < n ; ++ i ) Console . Write ( arr [ i ] ) ; } public static void Main ( ) { String str = " GEEKSFORGEEKS " ; int n = 3 ; printZigZagConcat ( str , n ) ; } }