Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C please Often times we end up using same functions in verity of different pr

ID: 3721627 • Letter: I

Question

In C please

Often times we end up using same functions in verity of different programs. Instead of rewriting these functions each time we write a program, one good practice is to create your own library of reusable functions. Make a header library functions.h and write all the functions used in the following C program that are not part of the standard or math library Note that Normal function normalize the given array. Definition of normalization can be found on middle of page 287 of your textbook b. #include include "functions.h" #define Size 100 int main () double List[Size]; int i, length printf ("Enter the length of your array (whole number between 1 and 100):" scanf ("%d", &length;); printf("Enter all %d elements of the array using space/return key: ", length); for (í = 0; ?

Explanation / Answer

I've implemented the required functions. Please review them and let me know if any modifications needs to be done.

############################## functions.h ###################################

#include <stdlib.h>

#include <stdio.h>

#include <math.h>

#define Size 100

double LogNabs(double number, int base) {

// compute the absolute value of the number

number = fabs(number);

// using maths, (log n base r) = (log n) / (log r)

return (log(number)/log(base));

}

double Median(double array[], int length) {

// first sort the array

double temp;

int i, j;

  

// make a copy of the array to preserve the order of elements in original array

double sortArray[Size];

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

sortArray[i] = array[i];

}

for(i = 0; i < length-1; i++) {

for(j= i+1; j < length; j++) {

if(sortArray[j] < sortArray[i]) {

// swap the two elements

temp = sortArray[i];

sortArray[i] = sortArray[j];

sortArray[j] = temp;

}

}

}

// if length is even, median is the mean of the two middle elements

// else median is the (length/2)th element

if(length%2==0) {

// if there is an even number of elements, return mean of the two elements in the middle

return((sortArray[length/2] + sortArray[length/2 - 1]) / 2.0);

} else {

// else return the element in the middle

return sortArray[length/2];

}

}

void Normal(double* array, int length) {

// I'm using the below definition of normalization.

// Normalized x= (x-min(array))/(max(array)-min(array))

// first find the max and min of the array

int i;

double max = array[0];

double min = array[0];

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

if (array[i] > max) {

max = array[i];

}

if (array[i] < min) {

min = array[i];

}

}

// if max == min, then normalization is undefined

// so return the original array

if (max == min) {

printf("Normalization is undefined for the array ");

return;

}

// now normalize the values

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

array[i] = (array[i]-min)/(max-min);

}

}

######################################## End of code #######################################

Sample Input:
3
2 1 3

Sample output:

Enter the length of your array (whole number between 1 and 100):

Enter all 3 elements of the array using space/return key:

Log base 3 of your list are:
0.6309 0.0000 1.0000

Median Value = 2.000000

Normalized list:
0.5000 0.0000 1.0000

Sample Input:

3
2.4 3.1 0.1

Sample Output:

Enter the length of your array (whole number between 1 and 100):

Enter all 3 elements of the array using space/return key:

Log base 3 of your list are:
0.7969 1.0298 -2.0959

Median Value = 2.400000

Normalized list:
0.7667 1.0000 0.0000

Sample Input:

3
2.4 -3.1 0.1

Sample Output:

Enter the length of your array (whole number between 1 and 100):

Enter all 3 elements of the array using space/return key:

Log base 3 of your list are:
0.7969 1.0298 -2.0959

Median Value = 0.100000

Normalized list:
1.0000 0.0000 0.5818