M4ritimeSeeker

PASS Week 9: Arrays

Oct 26th, 2021 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. PROBLEM #1: Reversing Arrays (With TWO arrays)
  2.  
  3. Write a program that creates an array of 5 integer values {1, 2, 3, 4, 5}, and reverses it.
  4.  
  5. You will have about 4 loops total. One to fill the first array (Array A) with values,
  6. a second one to print Array A, a third one to fill the second array (Array B) with A's values backwards,
  7. and a fourth one to print Array B.
  8.  
  9. SAMPLE OUTPUT
  10.  
  11. A: 1 2 3 4 5
  12. B: 5 4 3 2 1
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. PROBLEM #2: Creating a Login ID for a User
  28.  
  29. Just a note from Justin, this problem is pretty tricky. If you want easier problems first,
  30. skip this one and come back to it later.
  31.  
  32. Write a program that asks user to enter in their first name, last name,
  33. and the last 4 digits of their social security number, and makes a custom User ID from them.
  34.  
  35. Take the user's input and store it into 3 separate arrays. Use scanf() and the %s format specifier.
  36. ALSO MAKE SURE TO HAVE #include <string.h> AT THE TOP OF YOUR PROGRAM.
  37.  
  38. You will also create a fourth array to store the user ID itself. Here is the format:
  39. userID = [First 3 letters of LAST name][First 2 letters of FIRST name][Last 4 digits of SSN]
  40.  
  41. Then print the login ID afterward.
  42. ****IMPORTANT****
  43. Before you print the userID, include the following line of code RIGHT ABOVE THE printf:
  44. userID[9] = '\0';
  45. Change the "userID" portion to whatever you named the array that stores the User ID.
  46.  
  47.  
  48. SAMPLE OUTPUT:
  49.  
  50. Enter in your first name: Justin
  51. Enter in your last name: Bentley
  52. Enter in the last 4 digits of your SSN: 1111
  53.  
  54. Unique User ID is BenJu1111
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. PROBLEM #3: Reversing Arrays (With ONE array)
  74.  
  75. Write a program that reverses an array without using a second array like problem #1.
  76. The array will contain ten integers {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  77.  
  78. The last element
  79. becomes the first, the second from last becomes second, and so forth. The function
  80. is to reverse the elements in place, i.e., without using a second array. You can use
  81. a variable to hold an element temporarily. Then write a test driver to test the
  82. function using i) using even number of elements and ii) using an odd number of
  83. elements. The test driver will be your main function. You can call your function
  84. twice in the test driver, once with an odd sized array and the second with an even
  85. sized array of values.
  86.  
  87. SAMPLE OUTPUT
  88.  
  89. Array before reversing: 1 2 3 4 5 6 7 8 9 10
  90. Array after reversing: 10 9 8 7 6 5 4 3 2 1
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. PROBLEM #4: Checking ISBN Numbers
  110.  
  111. The International Standard Book Number, ISBN, is used to uniquely identify a book.
  112. It is made of 10 digits. Write a function that tests an ISBN to see if it is valid.
  113.  
  114. For an ISBN number to be valid, the weighted sum of the 10 digits must be evenly divisible by 11.
  115.  
  116. To determine the weighted sum, the value of each position is multiplied by its
  117. relative position, starting from the right, and the sum of the product is determined.
  118. If (weighted sum) modulus 11 is 0, the ISBN number is valid.
  119.  
  120. Test your function with examples, use Amazon to get valid book ISBNs.
  121.  
  122. Example
  123. ISBN: 0-07-881809-5 (assume no dashes in your function)
  124.  
  125. Code * Weight = Value
  126. 0 10 0
  127. 0 9 0
  128. 7 8 56
  129. 8 7 56
  130. 8 6 48
  131. 1 5 5
  132. 8 4 32
  133. 0 3 0
  134. 9 2 18
  135. 5 1 5
  136.  
  137. Weighted Sum is 220
  138.  
  139. 220 % 11 = 0 (Valid ISBN)
  140.  
  141.  
  142.  
  143.  
  144. SAMPLE OUTPUT (ISBN is 0078818095)
  145.  
  146. Enter in 10 numbers one at a time: 0
  147. Enter in 10 numbers one at a time: 0
  148. Enter in 10 numbers one at a time: 7
  149. Enter in 10 numbers one at a time: 8
  150. Enter in 10 numbers one at a time: 8
  151. Enter in 10 numbers one at a time: 1
  152. Enter in 10 numbers one at a time: 8
  153. Enter in 10 numbers one at a time: 0
  154. Enter in 10 numbers one at a time: 9
  155. Enter in 10 numbers one at a time: 5
  156. Weighted Sum is: 220
  157. The ISBN is valid
  158.  
Add Comment
Please, Sign In to add comment