How to resolve the algorithm Luhn test of credit card numbers step by step in the Run BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Luhn test of credit card numbers step by step in the Run BASIC programming language
Table of Contents
Problem Statement
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test:
For example, if the trial number is 49927398716:
Write a function/method/procedure/subroutine that will validate a number with the Luhn test, and use it to validate the following numbers:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Luhn test of credit card numbers step by step in the Run BASIC programming language
Source code in the run programming language
card$(1) = "49927398716"
card$(2) = "49927398717"
card$(3) = "1234567812345678"
card$(4) = "1234567812345670"
for i = 1 to 4
print card$(i);" ";luhn$(card$(i))
next i
FUNCTION luhn$(card$)
lc = len(card$)
for i = lc to 1 step -1
digit = val(mid$(card$,i,1))
if ((lc -i) mod 2) = 0 then chkSum = chkSum + digit else chkSum = chkSum + int(digit * 2.2)
next i
if chkSum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"
end function
You may also check:How to resolve the algorithm Start from a main routine step by step in the Forth programming language
You may also check:How to resolve the algorithm Heronian triangles step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Morse code step by step in the Raku programming language
You may also check:How to resolve the algorithm List rooted trees step by step in the zkl programming language
You may also check:How to resolve the algorithm Bitmap/Midpoint circle algorithm step by step in the Tcl programming language