Created
July 9, 2014 21:39
-
-
Save oliverbooth/6ae6f0f009cc2be4bf8a to your computer and use it in GitHub Desktop.
Even checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bool is_even(int i) { | |
| char buf[10]; // Probably big enough | |
| float f = (float)i; | |
| f /= 2; | |
| sprintf(buf, "%lf", f); | |
| for (int ii = 0; ii < 10 - 1; ++ii) { | |
| if (buf[ii] == '.' && buf[ii+1] == '5') { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment