In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.