Question: How to create multiple .c and .h files connected to a Makefile in bash The main.c is shown below: //main.c #include #include #include avg.h #include

How to create multiple .c and .h files connected to a Makefile in bash

The main.c is shown below: //main.c

#include

#include #include "avg.h"

#include "sum.h" #define N 10 int main() {

int i;

float a[N];

srand(123);

for ( i = 0; i < N; i++ ) {

a[i] = ( (double) rand() )/ RAND_MAX;

printf( "%.2f ", a[i] );

}

printf( " " );

printf( "average: %.2f ", avg( a, N ) );

printf( "sum: %.2f ", sum( a, N ) );

return 0;

} Extend the code by adding a function maximum that computes the maximum of the input array, a function minimum that computes the minimum of the input array, a function average that computes the average of the input array and a sum function that computes the sum of the input array. The function for the minimum should be located in file min.c (with the header file min.h); the function for the maximum should be located in file max.c (with the header file max.h); the function for the sum should be located in file sum.c (with the header file sum.h) and the function for the average should be located in file avg.c (with the header file avg.h). After implementing these four functions, extend the code for the main function to also print out the maximum and minimum. The executable file should be named stats.

Example output: 0.21 0.69 0.78 0.40 0.53 0.10 0.64 0.35 0.72 0.03

average: 0.44

sum:4.44

max:0.78

min:0.03

The final code should thus be split into the following source and header files: main.c, avg.c, avg.h, sum.c, sum.h, min.c, min.h, max.c, max.h

Include a working makefile so that all I have to do is to run make and then run your code. Use target all that makes the executable, stats.The program does not expect any input from the user.

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!