text: Largest number divisible by 50 that can be formed from a given set of N digits consisting of 0 s and 7 s only | C # program of the above approach ; Print the largest number divisible by 50 ; Counting number of 0 s and 7 s ; If count of 7 is divisible by 50 ; If count of 7 is less than 5 ; If count of 7 is not divisible by 50 ; Count of groups of 5 in which count of 7 s can be grouped ; Driver Code ; Given array ; Size of the array
code: using System ; public class GFG { static void printLargestDivisible ( int [ ] arr , int N ) { int i , count0 = 0 , count7 = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) count0 ++ ; else count7 ++ ; } if ( count7 % 50 == 0 ) { while ( count7 != 0 ) { Console . Write ( 7 ) ; count7 -= 1 ; } while ( count0 != 0 ) { Console . Write ( 0 ) ; count0 -= 1 ; } } else if ( count7 < 5 ) { if ( count0 == 0 ) Console . Write ( " No " ) ; else Console . Write ( "0" ) ; } else { count7 = count7 - count7 % 5 ; while ( count7 != 0 ) { Console . Write ( 7 ) ; count7 -= 1 ; } while ( count0 != 0 ) { Console . Write ( 0 ) ; count0 -= 1 ; } } } public static void Main ( String [ ] args ) { int [ ] arr = { 0 , 7 , 0 , 7 , 7 , 7 , 7 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 7 , 7 } ; int N = arr . Length ; printLargestDivisible ( arr , N ) ; } }