HW.1.
A student
identification number consists of 5 digits and a control digit.
Control digit is calculated using the first 5 digits.
For example:
518894 is a valid ID number.
The control digit is calculated as follows:
Suppose ABCDE is an ID number. To calculate control digit, firstly,
A is multiplied by 2, and the digits of the product is summed to get X
C is multiplied by 2, and the digits of the product is summed to get Y
E is multiplied by 2, and the digits of the product is summed to get Z
Then, X+B+Y+D+Z is calculated to get SUM,
Lastly the control digit is calculated by subtracting SUM from the closest number which is multiple of 10 and greater than SUM.
For example: if ID=51889
2x5=10 ---> X=1+0 =1
2x8=16 ---> X=1+6 =7
2x9=18 ---> X=1+8 =9
SUM = 1+1+7+8+9 = 26
the closest number which is multiple of 10 and greater than SUM is : 30
so the control digit is 30-26 : 4
Write a complete C program which inputs 5 digits identification number, calculates and prints the control digit.
Notes:
Use suitable data types
there should not be spaces between the digits in the input