bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

luc070.c (1468B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 08 Feb 2026
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* 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).
      9 */
     10 
     11 /* Let Us C, Chap- 15 (Strings), Qn No.: C(b) */
     12 
     13 /* This file is auto-generated by a bot. */
     14 /* This code is not compiled; it is for reference only. */
     15 
     16 
     17 #include <stdio.h>
     18 #include <string.h>
     19 #include <stdlib.h>
     20 
     21 int main()
     22 {
     23     char isbn[15];
     24     int i, sum = 0, digit;
     25 
     26     printf("Enter 10-digit ISBN number: ");
     27     scanf("%s", isbn);
     28 
     29     /* The formula given is: d1 + 2d2 + 3d3 + ... + 10d10
     30        where di is the ith digit from the RIGHT.
     31        
     32        If input is "007462542X" (Length 10):
     33        isbn[0] is d10 (Weight 10)
     34        isbn[1] is d9  (Weight 9)
     35        ...
     36        isbn[9] is d1  (Weight 1)
     37     */
     38 
     39     for (i = 0; i < 10; i++)
     40     {
     41         // Handle 'X' which represents 10 in ISBN
     42         if (isbn[i] == 'X' || isbn[i] == 'x')
     43             digit = 10;
     44         else
     45             digit = isbn[i] - '0';
     46 
     47         // Weight is (10 - i)
     48         sum += digit * (10 - i);
     49     }
     50 
     51     printf("Calculated Checksum: %d\n", sum);
     52 
     53     if (sum % 11 == 0)
     54         printf("The ISBN number is Correct.\n");
     55     else
     56         printf("The ISBN number is Incorrect.\n");
     57 
     58     return 0;
     59 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror