text: Program to print Step Pattern | C # Program to print Step Pattern ; function to print the steps ; declare a flag ; traverse through all the characters in the string ; if the x value is 0. . then we must increment till n ... set flag to true ; if the x value is n - 1 then we must decrement till 0 ... set flag as false ; print x * s ; checking whether to increment or decrement x ; Driver code ; Get the String and the number n ; calling the function
code: public class solution { using System ; public static void steps ( string str , int n ) { bool flag = false ; int x = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( x == 0 ) { flag = true ; } if ( x == n - 1 ) { flag = false ; } for ( int j = 0 ; j < x ; j ++ ) { Console . Write ( " * " ) ; } Console . Write ( str [ i ] + " STRNEWLINE " ) ; if ( flag == true ) { x ++ ; } else { x -- ; } } } public static void Main ( string [ ] args ) { int n = 4 ; string str = " GeeksForGeeks " ; Console . WriteLine ( " String : ▁ " + str ) ; Console . WriteLine ( " Max ▁ Length ▁ of ▁ Steps : ▁ " + n ) ; steps ( str , n ) ; } }