Skip to content

Instantly share code, notes, and snippets.

@markusfisch
Created November 25, 2016 13:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markusfisch/1dc84513999186b1dba20ce00f6d5c6d to your computer and use it in GitHub Desktop.
Save markusfisch/1dc84513999186b1dba20ce00f6d5c6d to your computer and use it in GitHub Desktop.
Calculate a horizontal check sum
static int horizontal_check_sum(int number) {
int sum = 0;
for (int i = 1, mod = 0; mod != number; i *= 10) {
mod = number % (i * 10);
sum += mod / i;
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment