I’m trying to program it such that it would calculate the check digit of isbn 10 from isbn 13. Can anyone give some advice on how to carry it out?
Firstly, how do i actually loop through a 13 digit isbn, remove the prefixed 978 in front before i proceed on to calculate the check digit of the isbn10? Thank you in advance!:)
This is how you can remove the first 3 digits:
And as for your ISBN10:
The final character of a ten digit International Standard Book Number is a check digit computed so that multiplying each digit by its position in the number (counting from the right) and taking the sum of these products modulo 11 is 0. The digit the farthest to the right (which is multiplied by 1) is the check digit, chosen to make the sum correct. It may need to have the value 10, which is represented as the letter X. For example, take the ISBN 0-201-53082-1. The sum of products is
0×10 + 2×9 + 0×8 + 1×7 + 5×6 + 3×5 + 0×4 + 8×3 + 2×2 + 1×1 = 99 ≡ 0modulo 11. So the ISBN is valid.While this may seem more complicated than the first scheme, it can be validated simply by adding all the products together then dividing by 11. The sum can be computed without any multiplications by initializing two variables, t and sum, to 0 and repeatedly performing
t = t + digit; sum = sum + t;(which can be expressed in C as sum += t += digit;). If the final sum is a multiple of 11, the ISBN is valid.Taken from here.