Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool luhnCheck(long num)
- {
- int a = 2;
- int b;
- int total = 0;
- int incrementer = 0;
- long shift = 1;
- while(a != 0)
- {
- incrementer++;
- for(int i = 1; i<=incrementer; i++)
- {
- shift *= 100;
- }
- a = num % shift;
- b = a/(shift/10); //- a % (shift/10); // every other digit
- starting from the second to last one
- if(a!= 0)
- {
- total+= ((2*b) % 10) - ((2*b)/10); //sum of digits
- }
- }
- return total;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement