![]() |
VOOZH | about |
An ISBN (International Standard Book Number) is a 10 digit number that is used to identify a book.
The first nine digits of the ISBN number are used to represent the Title, Publisher and Group of the book and the last digit is used for checking whether ISBN is correct or not.
The first 9 digits of it, can take any value between 0 and 9, but the last digits, sometimes may take value equal to 10; this is done by writing it as ‘X’.
To verify an ISBN, calculate 10 times the first digit, plus 9 times the second digit, plus 8 times the third digit and so on until we add 1 time the last digit. If the final number leaves no remainder when divided by 11, the code is a valid ISBN.
Examples :
Input : 007462542X Output : Valid 007462542X = 10*0 + 9*0 + 8*7 + 7*4 + 6*6 + 5*2 + 4*5 + 3*4 + 2*2 + 1*10 = 176 Since 55 leaves no remainder when divided by 11, hence it is a valid ISBN. Input : 0112112425 Output : Invalid 0112112425 = 10*0 + 9*1 + 8*1 + 7*2 + 6*1 + 5*1 + 4*1 + 3*4 + 2*2 + 1*5 = 71 Since 71 is not divisible by 11, given number is not a valid ISBN.
Now, we design a program to accept a ten digit code from the user and then we will check whether a number is ISBN or not. Display an appropriate message.
Implementation:
Valid
Time Complexity: O(1),as loop is running for constant number of times.
Auxiliary Space: O(1), no extra space is required, so it is a constant.
The above code checks for ISBN 10. The recent version of ISBN is ISBN 13 (in 2005).