Question: Write a C program that reads a sequence of nine digit numbers from a file and outputs each number with a message indicating whether it
Write a C program that reads a sequence of nine digit numbers from a file and outputs each number with a message indicating whether it is or is not a valid SIN. You can use a negative number at the end of the file to signal the end of data or you can use the file handling features of C to determine the end of the file. You should read the numbers from the file as integers and define a function that extracts the individual digits into an array. You should use this array in performing the verification steps. You can use the same function to extract digits for the values described in the methodology below.
The file used to test your program should include the following numbers:
111111111
222222222
333333333
444444444
555555555
666666666
777777777
888888888
999999999
205446651
193456787
046454286 ... plus at least 3 more valid numbers
Write the output to a file. Each line in the file should have the number and a message as to whether or not it is valid.
Methodology: A SIN consists of nine digits. F
or example, 193456787 The verification can be done as follows:
1. Construct a four digit number from the digits in even numbered positions (2, 4, 6, 8) e. g. 9468
2. Multiply the number by 2 e.g. 18936
3. Add the digits of the number obtained in step 2 e.g. 1+8+9+3+6 = 27
4. Construct a five digit number from the digits in odd numbered positions (1, 3, 5, 7, 9) e.g. 13577
5. Add the digits of the number from step 4 e.g. 1+3+5+7+7 = 23 6. If the sum of the numbers constructed in steps 3 and 5 is a multiple of 10, the number is valid. Otherwise it is invalid.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
