Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 7733
- int sum = 0;
- int dd;
- for ( int i = 0; i < d.length; i++ )
- {
- // Is right-to-left position even?
- if ( i % 2 == 0 )
- {
- // If it is, set dd to twice the digit
- dd = 2 * d[i];
- // Add the sum of dd's digits to sum
- int tempsum = 0;
- while (dd != 0) {
- tempsum += dd;
- dd /= 10;
- }
- sum += tempsum ;
- }
- else
- {
- // If right-to-left position is odd,
- // add the digit to sum
- sum += d[i];
- }
- }
- valid = (sum % 10 == 0);
- int sum = 0;
- int dd;
- for ( int i = 0; i < e.length; i++ )
- {
- if((e.length - i) % 2 != 0)
- {
- dd = 2 * e[i];
- sum += ((dd % 10) + (dd / 10));
- }
- else
- sum += e[i];
- }
- checkdigit = (((sum / 10) + 1) * 10) - sum;
- if(checkdigit >= 10)
- checkdigit %= 10;
Add Comment
Please, Sign In to add comment