Using the vi editor, write a C program on the Sun cluster that obeys the following specification.
An International Standard Book Number (ISBN) is a code of 10 characters. Each book published has its own unique ISBN. The last (tenth) character of an ISBN is a check character that is used to validate an ISBN. The check character is computed from the rest of the ISBN as follows: First, compute the sum of the first digit plus two times the second digit plus three times the third digit, ..., plus nine times the ninth digit. The last (tenth) character is the remainder when this sum is divided by 11. If the remainder is 10, the last character is X. For example, the ISBN 0806509597 is valid because:
and 249 mod 11 is 7, which is the last digit of the ISBN.
Write a function with one parameter that is an array of characters. The
function returns true (1) if the array represents a valid ISBN and false
(0) otherwise. Write a main
program that prompts the user for an
ISBN, passes the ISBN to the function, and reports whether or not the ISBN
is valid.
More detailed specifications include:
~taw2/pub/isbn.ccontains some code that will help you get started, including the correct prototype for function
check
(the function you need to write),
and the definition of function toint
, which converts a character
such as '9' to the integer 9. For example, if isbn
is an array
of characters and the value of isbn
at index i
is the
character '3', then the expression:
toint(isbn[i])evaluates to the integer 3.