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 to fill the first array (Array A) with values,
- a second one to print Array A, a third one to fill the second array (Array B) with A's values backwards,
- and a fourth one 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
- Just a note from Justin, this problem is pretty tricky. If you want easier problems first,
- skip this one and come back to it later.
- 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:
- userID = [First 3 letters of LAST name][First 2 letters of FIRST name][Last 4 digits of SSN]
- Then print the login ID afterward.
- ****IMPORTANT****
- Before you print the userID, include the following line of code RIGHT ABOVE THE printf:
- userID[9] = '\0';
- Change the "userID" portion to whatever you named the array that stores the User ID.
- 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 function
- is to reverse the elements in place, i.e., without using a second array. You can use
- a variable to hold an element temporarily. Then write a test driver to test the
- function using i) using even number of elements and ii) using an odd number of
- elements. The test driver will be your main function. You can call your function
- twice in the test driver, once with an odd sized array and the second with an even
- sized array of values.
- 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
Add Comment
Please, Sign In to add comment