Number of even substrings in a string of digits | C # program to count number of substring which are even integer in a string of digits . ; Return the even number substrings . ; If current digit is even , add count of substrings ending with it . The count is ( i + 1 ) ; Driver code
using System ; public class GFG { static int evenNumSubstring ( string str ) { int len = str . Length ; int count = 0 ; for ( int i = 0 ; i < len ; i ++ ) { int temp = str [ i ] - '0' ; if ( temp % 2 == 0 ) count += ( i + 1 ) ; } return count ; } public static void Main ( ) { string str = "1234" ; Console . Write ( evenNumSubstring ( str ) ) ; } }