Title Requirements:
Enter the code:
#include <iostream> #include <cstdio> #include <stdlib.h>//import the C language header file, the function using namespace STD which will be used; void getln (int a[])//input data is reversed and stored in array a { char p=getchar (); if (p!= ' \ n ') getln (A-1);//When the ENTER key is not pressed, enter the else return recursively; int X=strtol (&p,null,10); Converts the input character to a decimal integer * (a) =x with the Strtol function in <stdlib.h>;} int main () { int x=0;//finally evaluated and int arr[15];//used to store input data getln (ARR+14);//input data for (int i=0; i<15; i++) { if ((i+1)%2==0)//The number is an even digit case { int y=arr[i]*2; if (Y > 9) { y-=9; } x + = y; } else x+=arr[i];//The number is an odd digit, if (x%10==0)//The success of { cout<< "success" <<endl; } else { cout<< "failed" <<endl; } return 0;}
Operation Result:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
OJ Brush Problem---credit card number check (Luhn algorithm)