luc070.c¶
Problem Statement
Write a program that receives a 10-digit ISBN number, computes the checksum (d1 + 2d2 + 3d3 + ... + 10d10), and reports whether the ISBN number is correct (sum divisible by 11).
Metadata¶
| Property | Detail |
|---|---|
| Author | Amit Dutta amitdutta4255@gmail.com |
| Date | 08 Feb 2026 |
| License | MIT License (See the LICENSE file for details) |
Actions¶
💡 You can print or save this file by opening Raw and using your browser.
Source Code¶
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char isbn[15];
int i, sum = 0, digit;
printf("Enter 10-digit ISBN number: ");
scanf("%s", isbn);
/* The formula given is: d1 + 2d2 + 3d3 + ... + 10d10
where di is the ith digit from the RIGHT.
If input is "007462542X" (Length 10):
isbn[0] is d10 (Weight 10)
isbn[1] is d9 (Weight 9)
...
isbn[9] is d1 (Weight 1)
*/
for (i = 0; i < 10; i++)
{
// Handle 'X' which represents 10 in ISBN
if (isbn[i] == 'X' || isbn[i] == 'x')
digit = 10;
else
digit = isbn[i] - '0';
// Weight is (10 - i)
sum += digit * (10 - i);
}
printf("Calculated Checksum: %d\n", sum);
if (sum % 11 == 0)
printf("The ISBN number is Correct.\n");
else
printf("The ISBN number is Incorrect.\n");
return 0;
}