Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This question has two parts. Write an algorithm for a function to perform the following task: The algorithm calculates the average of numbers stored only

  1. This question has two parts.
    1. Write an algorithm for a function to perform the following task: The algorithm calculates the average of numbers stored only in certain index positions in an integer array of size 100. The function receives an integer parameter k. Only values stored at index positions that are divisible byk (integer division) would take part in the calculation. Values stored in other index positions do not take part in the calculation. The algorithm returns the average value. The whole array may not be full, so a value called count will indicate how much of the array is full. Note that 0 <= count < 100.

-------------------------Start: Algorithm for Average Function ------------------

--------------------End: Algorithm for Average Function ---(10 marks)

  1. Using the C language implement your algorithm for question 2a as a function called Average. Instead of printing to the screen, function Average takes an array as one of its parameters and returns the average of the numbers stored in the array. Note that there could be other parameters, including k. Then write an complete modular C main program that tests the use of your function.Build, run and test your program. Copy the source code of the program into your answer below.

----------------Start: Complete C program for Average ------------------

------------End: Complete C program for Average ------(15 marks)

  1. This question has three parts
    1. Write an efficient C function called counter, which receives a few parameters. One of these parameters is an array of integer numbers. The array always has sorted numbers in ascending order and numbers can be duplicated. To have an efficient function, you need to make use of this fact when designing your function. This function counts the number of times the largest number appears in the array. As an example, if the array contains 2, 4, 7, 9, 9, 14, 16, the counter function will return 1, as the largest number is 16, and it only occurs once.

-------------------------Start: counter function in C ------------------

--------------------End: counter function in C ---(10 marks)

  1. Explain which parameter passing approach you are using for the parameters of the counter function and, why you are using that approach for each of the parameters.

-------------------------Start: Parameter passing approach ------------------

--------------------End: Parameter passing approach ---(5 marks)

  1. Write an complete modular C program to demonstrate the use of your counter function.Build, run and test your program. Copy the source code of the program into your answer below.

-------------------------Start: Complete C program ------------------

------------------End: Complete C program ---(10 marks)

*(there are no additional attachments or anything) please help.

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions