/* * Author : Amit Dutta * Date : 08 Feb 2026 * Repo : https://github.com/notamitgamer/bsc * License : MIT License (See the LICENSE file for details) */ /* Write a program that receives a 16-digit Credit Card number and checks whether it is valid using the Luhn algorithm variant described. */ /* Let Us C, Chap- 15 (Strings), Qn No.: C(c) */ /* This file is auto-generated by a bot. */ /* This code is not compiled; it is for reference only. */ #include #include #include int main() { char card[20]; int i, digit, sum = 0; printf("Enter 16-digit Credit Card number: "); scanf("%s", card); /* Rule: 1. Start with rightmost-1 digit (index 14) and multiply every other digit by 2. (These are indices 0, 2, 4, ..., 14) 2. Subtract 9 if result >= 10. 3. Add these results. 4. Add remaining digits (indices 1, 3, ..., 15). 5. If total sum is divisible by 10, it is valid. */ for (i = 0; i < 16; i++) { digit = card[i] - '0'; if (i % 2 == 0) // Indices 0, 2, 4... (Every other starting from left, which hits rightmost-1) { digit = digit * 2; if (digit >= 10) { digit = digit - 9; } } // Add to total sum (both modified and unmodified digits) sum += digit; } printf("Total Sum: %d\n", sum); if (sum % 10 == 0) printf("The Credit Card number is Valid.\n"); else printf("The Credit Card number is Invalid.\n"); return 0; }