Nambiar Number Generator | C # implementation of the approach . ; Function to return the Nambiar number of the given number ; If there is no digit to choose ; Choose the first digit ; Chosen digit 's parity ; To store the sum of the consecutive digits starting from the chosen digit ; While there are digits to choose ; Update the sum ; If the parity differs ; Return the current sum concatenated with the Numbiar number for the rest of the string ; Driver code
using System ; using System . Collections . Generic ; class GFG { static String nambiarNumber ( String str , int i ) { if ( i >= str . Length ) return " " ; int firstDigit = ( str [ i ] - '0' ) ; int digitParity = firstDigit % 2 ; int sumDigits = 0 ; while ( i < str . Length ) { sumDigits += ( str [ i ] - '0' ) ; int sumParity = sumDigits % 2 ; if ( digitParity != sumParity ) { break ; } i ++ ; } return ( " " + sumDigits + nambiarNumber ( str , i + 1 ) ) ; } public static void Main ( String [ ] args ) { String str = "9880127431" ; Console . WriteLine ( nambiarNumber ( str , 0 ) ) ; } }