Problem Description Link
For example, using the number 5181 2710 9900 0012:
1. Double the appropriate digits (5181 2710 9900 0012) to obtain the values:(5*2) 10, (8*2)16, (2*2)4, (1*2) 2, (9*2) 18, (0*2) 0, (0*2) 0, (1*2)2.
2. (10)->(1+0) , (16)->(1+6), 4, 2, (18)->(1+8), 0, 0, 2
Add up the digits of these values to get (1+0) + (1+6) + 4 + 2 + (1+8) + 0 + 0 + 2 = 25. The sum of the undoubled digits is 1+1+7+0+9+0+0+2 = 20, so the total is 20+25=45.
3. 45 does not end in a 0, so this credit card number is invalid.
Algorithm:
This is a simple you just see the following exampleFor example, using the number 5181 2710 9900 0012:
1. Double the appropriate digits (5181 2710 9900 0012) to obtain the values:(5*2) 10, (8*2)16, (2*2)4, (1*2) 2, (9*2) 18, (0*2) 0, (0*2) 0, (1*2)2.
2. (10)->(1+0) , (16)->(1+6), 4, 2, (18)->(1+8), 0, 0, 2
Add up the digits of these values to get (1+0) + (1+6) + 4 + 2 + (1+8) + 0 + 0 + 2 = 25. The sum of the undoubled digits is 1+1+7+0+9+0+0+2 = 20, so the total is 20+25=45.
3. 45 does not end in a 0, so this credit card number is invalid.
No comments:
Post a Comment
Write your comment - Share Knowledge and Experience