Example 81: Verify an ISBN Number
Learn how to verify an ISBN number.
We'll cover the following
Problem
To uniquely identify a book, a 10-digit ISBN number is used. The ISBN number is considered to be correct if the sum of the following statement is a multiple of 11, where denotes the ith digit from the right.
The digits to can take any value from 0 to 9, whereas can be any value from 0 to 10. The ISBN convention is to use the value X to denote 10.
Write a function that receives a 10-character ISBN number and reports whether the ISBN number is correct or not.
Example
Input | Output |
---|---|
1572224940 | Valid |
2572224945 | Invalid: Checksum error |
007222b | Invalid input |
Try it yourself
Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.