Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. bool luhnCheck(long num)
  2. {
  3. int a = 2;
  4. int b;
  5. int total = 0;
  6. int incrementer = 0;
  7. long shift = 1;
  8. while(a != 0)
  9. {
  10. incrementer++;
  11. for(int i = 1; i<=incrementer; i++)
  12. {
  13. shift *= 100;
  14. }
  15. a = num % shift;
  16. b = a/(shift/10); //- a % (shift/10); // every other digit
  17. starting from the second to last one
  18. if(a!= 0)
  19. {
  20. total+= ((2*b) % 10) - ((2*b)/10); //sum of digits
  21. }
  22.  
  23. }
  24.  
  25. return total;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement