

a formula to single out a number, starting with the ones and then as you can see, mod is muliplied by 10 to go over the second number. total of numbers located at locations numbered with odd numbers total of numbers * 2 located at locations numbered with even numbers

num is the number I am checking that has been singled out the location at which number I am checking mod stands for modules, and is used to single out each number as seen later If it means the credit card number is correct, else it is false. I would later add both variables and check if the total modulo ten was equal to 0. I would then increment the place by one and check the other numbers until I reach 16 (the max digits for a card). If that wasn't the case I would add the number I was in to totalOdd without multiplication. Modulo 10 is congruent to 0), the number is valid!Īnd to implement that, I looped through the whole number and if the number place I was in had a modulo 2 equal to 0 then I would multiply by two and add to a variable called totalEven. If the total’s last digit is 0 (or, put more formally, if the total Second-to-last digit, and then add those products’ digits together.Īdd the sum to the sum of the digits that weren’t multiplied by 2. Multiply every other digit by 2, starting with the number’s Iam trying to implement Luhn's algorithm in the C language to check credit card validity, for those who don't know.
