Guest User

Untitled

a guest
Jul 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. 7733
  2.  
  3.  
  4. int sum = 0;
  5. int dd;
  6.  
  7. for ( int i = 0; i < d.length; i++ )
  8. {
  9. // Is right-to-left position even?
  10. if ( i % 2 == 0 )
  11. {
  12. // If it is, set dd to twice the digit
  13. dd = 2 * d[i];
  14.  
  15. // Add the sum of dd's digits to sum
  16. int tempsum = 0;
  17. while (dd != 0) {
  18. tempsum += dd;
  19. dd /= 10;
  20. }
  21. sum += tempsum ;
  22. }
  23. else
  24. {
  25. // If right-to-left position is odd,
  26. // add the digit to sum
  27. sum += d[i];
  28. }
  29. }
  30.  
  31. valid = (sum % 10 == 0);
  32.  
  33.  
  34.  
  35. int sum = 0;
  36. int dd;
  37.  
  38. for ( int i = 0; i < e.length; i++ )
  39. {
  40. if((e.length - i) % 2 != 0)
  41. {
  42. dd = 2 * e[i];
  43. sum += ((dd % 10) + (dd / 10));
  44. }
  45. else
  46. sum += e[i];
  47. }
  48.  
  49. checkdigit = (((sum / 10) + 1) * 10) - sum;
  50.  
  51. if(checkdigit >= 10)
  52. checkdigit %= 10;
Add Comment
Please, Sign In to add comment