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 :
- 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) | SET 1(Basic approach)
- Check if a given string is a valid number (Integer or Floating Point) in Java | SET 2 (Regular Expression approach)
- 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
- C Program to Multiply two Floating Point Numbers
- Program to find GCD of floating point numbers
- Check if a point is inside, outside or on the ellipse
- Check whether the point (x, y) lies on a given line
- Check if a point is inside, outside or on the parabola
- Check whether a given point lies on or inside the rectangle | Set 3
- Check whether a given point lies inside a triangle or not
- How to check if a given point lies inside or outside a polygon?
- Check if a point lies on or inside a rectangle | Set-2
- Check whether a point lies inside a sphere or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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