Find the greater number closest to N having at most one non | C # program to implement the above approach ; Function to get closest greater number with at most non zero digit ; Stores the closest greater number with at most one non - zero digit ; Stores length of str ; Append 10 to the end of resultant string ; Append n - 1 times '0' to the end of resultant string ; Driver code
using System ; class GFG { public static string closestgtNum ( string str ) { string res = " " ; int n = str . Length ; if ( str [ 0 ] < '9' ) { res = res + ( char ) ( str [ 0 ] + 1 ) ; } else { res = res + '1' ; res = res + '0' ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { res = res + '0' ; } return res ; } static void Main ( ) { string str = "120" ; Console . WriteLine ( closestgtNum ( str ) ) ; } }