6 like 0 dislike
286 views

The 13-digit International Standard Book Number (ISBN) is a unique code that identifies a book commercially. The last digit is a check digit used for error detection. To calculate its value, each digit of the first twelve digits is alternately multiplied, from left to right, by 1 or 3. The products are summed up and divided by 10. The check digit is the remainder of the division subtracted from 10. If it is 10, it becomes 0. 

For example, assume that the first twelve digits are 978960931961.   

(a) (9*1 + 7*3 + 8*1 + 9*3 + 6*1 + 0*3 + 9*1 + 3*3 + 1*1 + 9*3 + 6*1 + 1*3) = 126 

(b) The check digit = 10 – (126 % 10) = 10 – 6 = 4  

So the valid ISBN is: 9789609319614

Write a program that reads a 13-digit ISBN and checks the last digit to see if it is valid or not. 

#Try 1:

Input:

9789609319614

Output: 

Valid ISBN

 

#Try 2:

Input:

9781482214505

Output: 

Valid ISBN

 

#Try 3:

Input:

9780132936493

Output: 

Invalid ISBN

 

[Normal] Coding (C) - asked in Introduction to Computer Programming I (C) by (12.1k points)
ID: 27171 - Available when: Unlimited - Due to: Unlimited

retagged by | 286 views
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.43.157
©2016-2024

No related questions found

12,783 questions
183,443 answers
172,219 comments
4,824 users