Question: This is a C programming lab. Complete the code by instruction in the comment. here is code: // when compiling this code use: gcc lab02a.c

This is a C programming lab. Complete the code by instruction in the comment.

here is code:

// when compiling this code use: gcc lab02a.c -lm // since gcc will not link in the math library without the flag -lm

#include #include #include #include

// 7. provide a function prototype for mysum

int main() {

int i; double array[100];

// puts random doubles into array srand(time(NULL)); for( i = 0; i < 100; i++) array[i] = (rand() / (double) RAND_MAX) * (rand() % 100);

/* in case you want to view array contents for( i = 0; i < 100; i++) printf("%.5f, ", array[i]); */

// 1. create a function pointer called ptr capable of taking one argument of type double // and returning a double

// 2. assign function ceiling (from the math library to ptr)

printf(" Average of array numbers using ceiling %.2f ", mysum(ptr, array, 100));

// 3. assign function floor (from the math library to ptr)

printf("Average of array numbers using floor %.2f ", mysum(ptr, array, 100));

// 4. assign function round (from the math library to ptr)

printf("Average of array numbers using round %.2f ", mysum(ptr, array, 100));

return 0; }

// returns the average of array values by first applying // some rounding function to the number and then using it in the computation double mysum( /* 5. create function pointer parameter called fn*/, double array[], int size) { int i; double accumulator = 0;

for (i = 0; i < size; i++) { accumulator += // 6. call function fn on array[i] }

return accumulator;

}

code ends

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!