Get the App
SLTechnology News&Howtos  ›  Development  › 

C # how to verify the credit card number

Shulou Source: shulou.com Published: 2022-06-02 02:19:14 10月04日 Update

Editor to share with you how to achieve credit card number verification, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article. Let's learn about it.

[verification of credit card number]

When you enter your credit card number, are you worried about the loss caused by the wrong input? Actually, you don't have to worry so much.

Because not a random credit card number is legal, it must be verified by the Luhn algorithm.

The process of the verification:

1. Start with the last digit of the card number and add the odd digits (1, 3, 5, etc.) in reverse.

2. Starting with the last digit of the card number, inversely multiply the even digit by 2 (if the product is two digits, subtract it by 9), and then sum.

3. add the sum of odd digits to the sum of even digits, and the result should be divisible by 10.

For example, the card number is 5432123456788881

Then, odd digits sum = 35

The result of multiplying even digits by 2 (some subtract 9): 1 6 2 6 1 5 7 7, summation = 35.

Finally, 35-35-70 can be divisible by 10, and the check is determined to pass.

Please write a program, enter the card number from the keyboard, and then determine whether the check is passed. By displaying: "success", otherwise "failure" is displayed.

For example, user input: 356827027232780

Program output: successful

[reference test case]

356406010024817 successful

358973017867744 successful

356827027232781 failed

306406010024817 failed

358973017867754 failed

Because there is no space in the middle of the data when entering. So use strings.

# include

Main ()

{

Char a [16] = {0}

Int sum1,sum2,temp

For (int jamboo witch junio witch iMurray 2)

{

Sum1+= (a [I] -'0')

}

For (int iTunes 13th I > 0f imuri 2)

{

Temp=2* (a [I] -'0')

If (temp > = 10)

{

Temp-=9

Sum2+=temp

}

Else

{

Sum2+=temp

}

}

If ((sum1+sum2) = = 0)

{

Printf ("success\ n")

}

Else

{

Printf ("failed\ n")

}

}

Return 0

}

The above is all the contents of the article "how to verify the credit card number of c #". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Card number digital credit success verification input number article censor credit card content number sum time program result reference legal not so much product Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Apple Shulou Tech Info Xiaomi OPPO Reno