Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will write a program (in C) that uses 2 arrays, both of size 20, and both declared in the main() function. Your program will

You will write a program (in C) that uses 2 arrays, both of size 20, and both declared in the main() function. Your program will allow the user to choose from 4 different ways of initializing each array. After each initialization, the array should be printed to the user to show it was initialized correctly by calling a printArray() function that you will write. Then your program will determine the inner product of the two arrays, showing the result. Since the user will be prompted twice for a choice of initialization, once for each of the two arrays, rather than repeating that block of code twice in the main() function, put it into a function called initialize(). This is the function that will present to the user the menu of initialization choices, and depending on the users choice, will call the appropriate initialization function. Each of the 4 array initializations will be a separate function, as will the inner product determination, and also the function to print the array. The menu to the user of the 4 different initialization choices should look something like the following: 1. all numbers from 1-20 2. the first 20 even numbers, beginning with 2 3. the first 20 odd numbers, beginning with 1 4. the first 20 fibonacci numbers, beginning with 0 and 1 The user will choose one of these 4 for each array. After the first choice is made, the first array will be initialized accordingly by sending it to the function for that initialization. After the second choice is made, the second array will be sent to the corresponding initialization function. From within the main() function, after initializing the arrays, call your print function for each array to see that the initializations work as expected. Then both initialized arrays will then be sent to the inner product function, and that function will return the inner product back to the main() function, where it will be printed to the user. For this lab, the size of the arrays should be a constant variable or a #define name, at the top of your program outside of all the functions. That value can then be used by all the functions, and it also allows for easy modification if later, the size would need to be changed. Use that constant variable or #defined name in your loops whenever the size is needed. Notes: Fibonacci numbers are a sequence of numbers where each successive number is the sum of the previous two. With ours, the first two are 0 and 1, so the third number would be 1, the next one would be 2, etc., as in the following: 0 1 1 2 3 5 8 13 The inner product of two arrays is the sum of the component-wise products. Suppose we have two arrays each containing 4 integers: a1[ ] = {1, 4, 3, 5} and a2[ ] = {2, -1, 1, 4}. The inner product of those two arrays would be: 1 * 2 + 4 * -1 + 3 * 1 + 4 * 5 = 2 - 4 + 3 + 20 = 21. 2 All together, including the main() function, your program should consist of 8 functions. The following function prototypes should be used: void initialize(int a[ ]); void all(int a[ ]); void even(int a[ ]); void odd(int a[ ]); void fib(int a[ ]); void printArray(int a[ ]); int innerProduct(int a[ ], int b[ ]); Turn In Work Show your ta that you completed the assignment. Then submit your lab8.c program using the handin page: http://handin.cs.clemson.edu Remember: 1. There should be no other global variables in your program points will be deducted if global variables are used. 2. Also ensure that there is no variable shadowing. 3. Your prototypes should appear at the top of your program. 4. Lastly, dont forget to include a comment preceding each function with a short description and also showing the inputs to and outputs from the function (parameters coming in and items being returned).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

3. Existing organizations and programs constrain behavior.

Answered: 1 week ago