Question: Write a C program that will create the hash value of a Student ID that is entered by the user. Note that the ID should
Write a C program that will create the hash value of a Student ID that is entered by the user. Note that the ID should be a 9-digit integer, but you dont need to do any input validity check. We assume that the user will enter correct input.
Your Student ID is a 9-digit number. You are going to hash it to a 4-digit integer using the following steps: Separate every three digits of the ID. We name them L (for the three left-most digits), M (for the three middle digits) and R (for the three right-most digits). Compute the summation of the digits of each L, M and R, and store them in the same locations, L, M and R, respectively. For instance, if L = 123, then L = 1+2+3 = 6. Or, for instance, if M=676, then M=6+7+6 = 19. If each of L, M and R is one digit. We are done in this step. However, if any of them is greater than 9, then we should repeat the digits summation until we reach to a single-digit number. For instance, in the above example, M=676, and therefore, M beomes 19, which is greater than 9. We repeat the digits summation on M. Because M= 19, therefore, M=1 +9 = 10. Again, M is greater than 9. We repeate the digits summation on M. M = 10, therefore, M=1 + 0 = 1. Now we stop. After this repetative step, each of L, M and R is only a single digit. Compute the summation of L, M and R, and put it into S. Same as the previous step, if S is greater than 9, we repeatedly do the digits summation until S becomes only a single-digit number. For instance, if at the end of the previous step L=6, M = 7, and R = 1, then S = 6+ 7+ 1 = 14. Now, Sis greater than 9. Therefore, we repeat the digits summation on the digits of S. S= 14, thus, S = 1 +4 = 5. Now, S is a single-digit number and we stop. The final four-digit hash value will be Hash= M* 1000+S + 100+ L + 10 + R. Write a C program that will create the hash value of a Student ID that is entered by the user. Note that the ID should be a 9-digit integer, but you don't need to do any input validity check. We assume that the user will enter correct input. Note: The digits separation should be done programatically. However, you should only use math operations to separate the digits. No function should be used for this purpose. Sample execution: Please enter a 9-digit integer: 108965676 The hash value of your ID(108965676) is 2391 Explanation: ID=108965676 L=108 M=965 R=676 L=1+0+8 = 9 M=9+6+5 = 20 M= 2 + 0 = 2 R=6+7+6= 19 R= 1 + 9 = 10 => R= 1+0=1 S=L+M+R=9+2+1 = 12 => S= 1 + 2 = 3 Hash= M* 1000+S* 100+L* 10+R=2* 1000 + 3 * 100+9 * 10+1 = 2391 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
