Skip to content

Commit 25d4dcd

Browse files
authored
Update README.md
1 parent 04c04e7 commit 25d4dcd

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

README.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,63 @@
1-
# Luhn_Algorithm
1+
# Luhn_Algorithm
2+
This C program validates a 16-digit number using the Luhn algorithm, a simple checksum formula used to validate identification numbers such as credit card or debit card numbers.
3+
4+
## ✅ Features
5+
Validates input length (must be exactly 16 digits)
6+
7+
Ensures all characters are numeric
8+
9+
Implements Luhn's checksum logic:
10+
11+
Doubles every second digit from the left (starting at index 0)
12+
13+
Subtracts 9 from any result greater than 9
14+
15+
Sums the remaining digits
16+
17+
Prints whether the number is valid or invalid as per Luhn’s algorithm
18+
19+
## 📌 How It Works
20+
Input: The user is prompted to enter a 16-digit number.
21+
22+
Validation:
23+
24+
Checks if the number has exactly 16 digits
25+
26+
Rejects if any non-numeric character is present
27+
28+
Processing:
29+
30+
Doubles digits at even indices (0, 2, 4, ..., 14), adjusts if >9
31+
32+
Adds digits at odd indices (1, 3, ..., 15) directly
33+
34+
Result:
35+
36+
If total sum is divisible by 10, the number is considered valid
37+
38+
Otherwise, it is invalid.
39+
40+
----
41+
42+
## 🛠 Example
43+
```c
44+
Enter the number: 4539578763621486
45+
4539578763621486 passes Luhn's Algorithm.
46+
```
47+
48+
## 📂 Function Definition
49+
```c
50+
int Luhn_Algorithm();
51+
```
52+
53+
## 📚 Dependencies
54+
<stdio.h>
55+
56+
<string.h>
57+
58+
<ctype.h>
59+
60+
## 🧠 Why Use This?
61+
This is a useful utility for learning how credit card validation works under the hood, practicing digit manipulation, and understanding input validation techniques in C.
62+
63+
----

0 commit comments

Comments
 (0)