Check whether given floating point number is even or odd | C # program to check whether given floating point number is even or odd ; Function to check even or odd . ; Loop to traverse number from LSB ; We ignore trailing 0 s after dot ; If it is ' . ' we will check next digit and it means decimal part is traversed . ; If digit is divisible by 2 means even number . ; Driver function
using System ; public class GfG { public static bool isEven ( string s1 ) { int l = s1 . Length ; bool dotSeen = false ; for ( int i = l - 1 ; i >= 0 ; i -- ) { if ( s1 [ i ] == '0' && dotSeen == false ) continue ; if ( s1 [ i ] == ' . ' ) { dotSeen = true ; continue ; } if ( ( s1 [ i ] - '0' ) % 2 == 0 ) return true ; return false ; } return false ; } public static void Main ( ) { string s1 = "100.70" ; if ( isEven ( s1 ) ) Console . WriteLine ( " Even " ) ; else Console . WriteLine ( " Odd " ) ; } }