Subject: PRF192-PFC Workshop 06 Objectives: Managing Arrays
Subject: PRF192-PFC Workshop 06 Objectives: Managing Arrays
Subject: PRF192-PFC Workshop 06 Objectives: Managing Arrays
Workshop 06
SIN: 193 456 787 | check digit is 7 add first set of alternates to themselves
9 4 6 8 9 4 6 8 18 8 12 16
add the digits of each sum 1+8+8+1+2+1+6 = 27 (T1)
add the other alternates 1+3+5+7 = 16 (T2)
total = T1+T2 = 27+16=43
Next highest integer multiple of 10 T3= 50 (50>43).
Difference T3-total = 50-43= 7 Matches the check digit, therefore this SIN is valid
SIN: 193456787
N0 N1 N2 N3 N4 N5 N6 N7 N8 N9
1 9 3 4 5 6 7 8 7
9 4 6 8 9 4 6 8 18 8 12 16
C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12
Problem 1 (4 marks)
An ISBN consists of exactly 10 digits. The rightmost digit is the check digit. The check digit is
validated modulo 11.
multiply each digit from the first to the ninth by a weight from 10 to 2 respectively (the first
digit by 10, the second by 9,..., the ninth by 2).
the sum of the products plus the check digit should be divisible without remainder by 11.
if there is a remainder, the whole number is not a valid ISBN.
Consider the following example:
ISBN 0003194876 | check digit is 6 add first set of alternates to themselves
0 0 0 3 1 9 4 8 7 10 9 8 7 6 5 4 3 2 0 0 0 21 6 45 16 24 14 = 126
add check digit 6 total 132 divide by 11 12 remainder 0 Therefore this ISBN is valid.
I1 I2 I3 I4 I5 I6 I7 I8 I9 I10
0 0 0 3 1 9 4 8 7 6
C1 C2 C3 C4 C5 C6 C7 C8 C9
0*10=0 0*9=0 0*8=0 3*7=21 1*6=6 9*5=45 4*4=16 8*3=24 7*2=14
Write a program that will accept a number (>=1 000 000 000) then show whether the number is an ISBN or
not.
Problem 2 (6 marks)
Develop a C-program that helps user managing an 1-D array of real numbers(maximum of 100 elements) ,
with initial number of elements is 0, using the following simple menu:
1- Add a value
2- Search a value
3- Print out the array
4- Print out values in a range
5- Print out the array in ascending order
6- Print out the array in descending order
7- Remove the first existence of a value
8- Remove all existences of a value
Others- Quit
- When the option 1 is selected, user will enters a value then it is added to the array
- When the option 2 is selected, user will enters a value then number of it’s existences will be printed out.
- When the option 3 is selected, values in the array will be printed out.
- When the option 4 is chosen, user will enter 2 values, minVal and maxVal, the values in array which are
between minVal and maxVal are printed out (minVal <=value<=maxVal)
- When the option 5 is chosen, values in array will be printed out in ascending order but their position
are preserved. ( sorting based their pointers only) (tham khảo trong slide, sử dụng một mảng
phụ và thực hiện sắp xếp ở trong mảng đó để mảng chính bên ngoài không bị ảnh hưởng)
- When the option 6 is chosen, values in array will be printed out in descending order but their position
are preserved. ( sorting based their pointers only) (tham khảo trong slide, sử dụng một mảng
phụ và thực hiện sắp xếp ở trong mảng đó để mảng chính bên ngoài không bị ảnh hưởng)
- When the option 7 is selected, remove the first existence of a value. (trường hợp giá trị đó ở nhiều vị trí
trong mảng thì chỉ xoá vị trí đầu tiên xuất hiện, tham khảo slide)
- When the option 8 is selected, remove all existences of a value (trường hợp giá trị đó ở nhiều vị trí
trong mảng thì xoá hết tất cả vị trí đó, tham khảo slide)