Number of subsequences in a given binary string divisible by 2 | C # implementation of the approach ; Function to return the count of the required subsequences ; To store the final answer ; Multiplier ; Loop to find the answer ; Condition to update the answer ; updating multiplier ; Driver code
using System ; class GFG { static int countSubSeq ( string str , int len ) { int ans = 0 ; int mul = 1 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str [ i ] == '0' ) ans += mul ; mul *= 2 ; } return ans ; } static public void Main ( ) { string str = "10010" ; int len = str . Length ; Console . WriteLine ( countSubSeq ( str , len ) ) ; } }