-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathch4_prog_proj_05.c
39 lines (30 loc) · 1.09 KB
/
ch4_prog_proj_05.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*********************************************************
* From C PROGRAMMING: A MODERN APPROACH, Second Edition *
* By K. N. King *
* Copyright (c) 2008, 1996 W. W. Norton & Company, Inc. *
* All rights reserved. *
* This program may be freely distributed for class use, *
* provided that this copyright notice is retained. *
*********************************************************/
// (Section 4.1, Pages 57-58)
/*
* ch4_prog_proj_05.c
*
* Created on: Apr 1, 2024
* Author: Mahmoud Hamdy
*/
// Programming Project 5: Computing a UPC check digit (Rewritten)
#include <stdio.h>
int main(void)
{
int d, i1, i2, i3, i4, i5, j1, j2, j3, j4, j5,
first_sum, second_sum, total;
printf("Enter the first 11 digits of a UPC: ");
scanf("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d",
&d, &i1, &i2, &i3, &i4, &i5, &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;
printf("Check digit: %d\n", 9 - ((total - 1) % 10));
return 0;
}