Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PROBLEM #1: Reversing Arrays (With TWO arrays)
- Write a program that creates an array of 5 integer values {1, 2, 3, 4, 5}, and reverses it.
- You will have about 4 loops total. One loop to fill the first array (Array A) with values,
- a second loop to print Array A, a third loop to fill the second array (Array B) with A's values backwards,
- and a fourth loop to print Array B.
- SAMPLE OUTPUT
- A: 1 2 3 4 5
- B: 5 4 3 2 1
- PROBLEM #2: Creating a Login ID for a User
- Write a program that asks user to enter in their first name, last name,
- and the last 4 digits of their social security number, and makes a custom User ID from them.
- Take the user's input and store it into 3 separate arrays. Use scanf() and the %s format specifier.
- ALSO MAKE SURE TO HAVE #include <string.h> AT THE TOP OF YOUR PROGRAM.
- You will also create a fourth array to store the user ID itself. Here is the format:
- [First 3 letters of LAST name][First 2 letters of FIRST name][Last 4 digits of SSN]
- Then print the login ID afterward.
- ***IMPORTANT***
- As you can tell from the %s, this problem involves using strings. I (Justin) know that strings are in
- this week's module and not last week's, so you may have to consult the canvas module for strings to see
- how to take them as input. I don't know why this problem was here instead of next week ¯\_(ツ)_/¯
- HOWEVER, fortunately, you don't need to know strings forward and back to complete it.
- Once you get the two strings as input, you can just treat them as normal arrays. No bells and whistles attached.
- SAMPLE OUTPUT:
- Enter in your first name: Justin
- Enter in your last name: Bentley
- Enter in the last 4 digits of your SSN: 1111
- Unique User ID is BenJu1111
- PROBLEM #3: Reversing Arrays (With ONE array)
- Write a program that reverses an array without using a second array like problem #1.
- The array will contain ten integers {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
- The last element
- becomes the first, the second from last becomes second, and so forth. The purpose
- is to reverse the elements in place, i.e., without using a second array. You can use
- a variable to hold an element temporarily. Try it out with an array with an even number of
- elements and one with an odd amount of elements!
- SAMPLE OUTPUT
- Array before reversing: 1 2 3 4 5 6 7 8 9 10
- Array after reversing: 10 9 8 7 6 5 4 3 2 1
- PROBLEM #4: Checking ISBN Numbers
- The International Standard Book Number, ISBN, is used to uniquely identify a book.
- It is made of 10 digits. Write a function that tests an ISBN to see if it is valid.
- For an ISBN number to be valid, the weighted sum of the 10 digits must be evenly divisible by 11.
- To determine the weighted sum, the value of each position is multiplied by its
- relative position, starting from the right, and the sum of the product is determined.
- If (weighted sum) modulus 11 is 0, the ISBN number is valid.
- Test your function with examples, use Amazon to get valid book ISBNs.
- Example
- ISBN: 0-07-881809-5 (assume no dashes in your function)
- Code * Weight = Value
- 0 10 0
- 0 9 0
- 7 8 56
- 8 7 56
- 8 6 48
- 1 5 5
- 8 4 32
- 0 3 0
- 9 2 18
- 5 1 5
- Weighted Sum is 220
- 220 % 11 = 0 (Valid ISBN)
- SAMPLE OUTPUT (ISBN is 0078818095)
- Enter in 10 numbers one at a time: 0
- Enter in 10 numbers one at a time: 0
- Enter in 10 numbers one at a time: 7
- Enter in 10 numbers one at a time: 8
- Enter in 10 numbers one at a time: 8
- Enter in 10 numbers one at a time: 1
- Enter in 10 numbers one at a time: 8
- Enter in 10 numbers one at a time: 0
- Enter in 10 numbers one at a time: 9
- Enter in 10 numbers one at a time: 5
- Weighted Sum is: 220
- The ISBN is valid
Advertisement
Add Comment
Please, Sign In to add comment