/* Computes a Universal Product Code check digit */ /* A UPC has twelve-digits, like this: 0 37000 00407 3 The last digit is a "check digit" to verify the first eleven were read properly. Compute the check digit as follows: Add together digits 1, 3, 5, 7, 9, 11. Add together digits 2, 4, 6, 8, 10. Multiply the first sum by 3 and add it to the second sum. Subtract 1 from the total. Compute the remainder when divided by 10. Subtract the remainder from 9. */ #include int main(void) { int d, i1, i2, i3, i4, i5, j1, j2, j3, j4, j5, first_sum, second_sum, total; int result; printf("Enter the first (single) digit: "); scanf("%1d", &d); printf("Enter first group of five digits: "); scanf("%1d%1d%1d%1d%1d", &i1, &i2, &i3, &i4, &i5); printf("Enter second group of five digits: "); scanf("%1d%1d%1d%1d%1d", &j1, &j2, &j3, &j4, &j5); first_sum = d + i2 + i4 + j1 + j3 + j5; second_sum = i1 + i3 + i5 + j2 + j4; total = 3 * first_sum + second_sum; result = 9 - ((total - 1) % 10); printf("The computed check digit is: %d\n", result); return 0; }