CSE 101 Lecture Notes - Lecture 7: Luhn Algorithm

25 views1 pages

Document Summary

Counter-driven loops involves a variable (such as i) called a counter that controls the number of iterations (or repetitions) of the loop. For-loops are better suited for counter-driven loops (when we know how many iterations we need) While loops are used when the number of iterations to be completed cannot be computed. Input validation repeatedly prompts the user to enter valid data every time invalid data is entered. Common application for interactive programs to perform error-checking of the input. Luhn algorithm checks if an account number (i. e. credit card number) is valid. Odd-positioned digits are added as-is to a running total. If that value is less than 10, add it to the running total. Otherwise, add the two digits individually to the running total. If the sum is a multiple of 10, the account number is valid, otherwise, it isn t. Example: 79927398713, odd-positioned digits (7, 9, 7, 9, 7, 3), added right to left gives.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents