Given a floating point number, check whether it is even or odd.
We can check whether a integer is even or odd by dividing its last digit by 2. But in case of floating point number we can’t check a given number is even or odd by just dividing its last digit by 2. For example, 100.70 is an odd number but its last digit is divisible by 2.
Input : 100.7 Output : odd Input : 98.8 Output : even Input : 100.70 Output : odd Trailing 0s after dot do not matter.
- We start traversing a number from its LSB until we get a non-zero digit or ‘.’
- If the number is divisible by 2 it is even else odd
- If it is ‘.’ than it means decimal part of number is traversed and now we can check number is even or odd by dividing number by 2 whether it is 0 or non zero digit.
Below is the implementation of above approach :
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check whether the given floating point number is a palindrome
- Check if a given string is a valid number (Integer or Floating Point) | SET 1(Basic approach)
- Check if a given string is a valid number (Integer or Floating Point) in Java
- Check if a given string is a valid number (Integer or Floating Point) in Java | SET 2 (Regular Expression approach)
- Check if a number has an odd count of odd divisors and even count of even divisors
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Check whether a given number is even or odd
- Check whether XOR of all numbers in a given range is even or odd
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Check whether count of odd and even factors of a number are equal
- Smallest number to multiply to convert floating point to natural
- Fast method to calculate inverse square root of a floating point number in IEEE 754 format
- Check whether product of 'n' numbers is even or odd
- Queries to check whether bitwise AND of a subarray is even or odd
- Program to find GCD of floating point numbers
- C Program to Multiply two Floating Point Numbers
- Sum of two large Floating-point numbers
- Check whether a given point lies inside a triangle or not
- Check whether a given point lies on or inside the rectangle | Set 3
- Check whether the point (x, y) lies on a given line
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : jit_t