Tuesday, March 1, 2011

Arrays

Every book published by international publishers should carry an International Standard Book Number (ISBN). It is a 10 character 4 part number as shown below.
0-07-041183-2
The first part denotes the region, the second represents publisher, the third identifies the book and the fourth is the check digit. The check digit is computed as follows:
Sum = (1 x first digit) + (2 x second digit) + (3 x third digit) + ...... + (9 x ninth digit).
Check digit it the remainder when sum is divided by 11. Write a program that reads a given ISBN number and checks whether it represents a valid ISBN.

#include <stdio.h>
void main()
{
int a[20],i,sum,rem;
clrscr();
printf("Enter 10 digit ISBN no. of Your Book enter every digit with one space\n");
for(i=1;i<=10;i++)
scanf("%d",&a[i]);
sum=(a[1]*1)+(a[2]*2)+(a[3]*3)+(a[4]*4)+(a[5]*5)+(a[6]*6)+(a[7]*7)+(a[8]*8)+(a[9]*9);
rem=sum%11;
if(rem==a[10])
printf("This is a valid ISBN No.");
else
printf("This is wrong ISBN No.");
getch();
}

OUTPUT
Enter 10 digit ISBN no. of Your Book enter every digit with one space
0 0 7 0 4 1 1 8 3 2
This is a valid ISBN No.

Enter 10 digit ISBN no. of Your Book enter every digit with one space
0 0 7 0 4 1 1 8 3 3
This is wrong ISBN No.

1 comment:

  1. What can i do if i want to enter 10 digit isbn number with hyphen dash between them

    ReplyDelete