Created
November 25, 2016 13:17
-
-
Save markusfisch/1dc84513999186b1dba20ce00f6d5c6d to your computer and use it in GitHub Desktop.
Calculate a horizontal check sum
This file contains 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
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