Skip to content

Instantly share code, notes, and snippets.

@oliverbooth
Created July 9, 2014 21:39
Show Gist options
  • Select an option

  • Save oliverbooth/6ae6f0f009cc2be4bf8a to your computer and use it in GitHub Desktop.

Select an option

Save oliverbooth/6ae6f0f009cc2be4bf8a to your computer and use it in GitHub Desktop.
Even checker
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