Your job is to implement two functions: 1. int *scan_array(int size);, which should scan in size integers and store them

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Your job is to implement two functions: 1. int *scan_array(int size);, which should scan in size integers and store them

Post by answerhappygod »

Your Job Is To Implement Two Functions 1 Int Scan Array Int Size Which Should Scan In Size Integers And Store Them 1
Your Job Is To Implement Two Functions 1 Int Scan Array Int Size Which Should Scan In Size Integers And Store Them 1 (156.05 KiB) Viewed 47 times
Your job is to implement two functions: 1. int *scan_array(int size);, which should scan in size integers and store them in a malloc'd array. It should then return the malloc'd array. 2. int calculate_average (int *array, int size);, which should calculate and return the average of all elements of array. DANGER: You won't be able to complete this exercise without using the function malloc to create the array. If you attempt to create the array as a local variable e.g. int array [size]; and then return it, your code will likely crash and give you a headache. HINT: To use malloc, you'll need to calculate how many bytes to allocate to your array. How might sizeof(int) help you with this? You'll also need to #include stdlib.h to be able to access the malloc function. The output from your program should look exactly like this: ./mallocd_array Enter size: 5 Enter 5 integers: 1 2 3 4 5 The average of all values in the array is: 3.00 ./mallocd_array Enter size: 1 Enter 1 integers: 10 The average of all values in the array is: 10.00 ./mallocd_array Enter size: 3 Enter 3 integers: 5 -4 -3 The average of all values in the array is: -0.67
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply