text: Program to check if a given number is Lucky ( all digits are different ) | C # program to check if a given number is lucky ; This function returns true if n is lucky ; Create an array of size 10 and initialize all elements as false . This array is used to check if a digit is already seen or not . ; Traverse through all digits of given number ; Find the last digit ; If digit is already seen , return false ; Mark this digit as seen ; Remove the last digit from number ; Driver code
code: using System ; class GFG { static bool isLucky ( int n ) { bool [ ] arr = new bool [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) arr [ i ] = false ; while ( n > 0 ) { int digit = n % 10 ; if ( arr [ digit ] ) return false ; arr [ digit ] = true ; n = n / 10 ; } return true ; } public static void Main ( ) { int [ ] arr = { 1291 , 897 , 4566 , 1232 , 80 , 700 } ; int n = arr . Length ; for ( int i = 0 ; i < n ; i ++ ) if ( isLucky ( arr [ i ] ) ) Console . Write ( arr [ i ] + " ▁ is ▁ Lucky ▁ STRNEWLINE " ) ; else Console . Write ( arr [ i ] + " ▁ is ▁ not ▁ Lucky ▁ STRNEWLINE " ) ; } }