Example 81: Verify an ISBN Number

Learn how to verify an ISBN number.

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 did_{i} denotes the ith digit from the right.

d1+2d2+3d3+....+10d10d_{1} + 2d_{2} + 3d_{3} + .... + 10d_{10}

The digits d2d_{2} to d9d_{9} can take any value from 0 to 9, whereas d1d_{1} 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.