Write C Program

For a series Of numbers with n elements Xo, Xl,X2,

- Calculate mean g and variance var: g = Var= g)
- Carry Out sorting: ascending or descending.

For the implementation in C applies:

- A function (name e.g., output) should be created for the output of the series of numbers. In addition to the call parameters for the series of numbers, the function output should have another call parameter: a pointer to a character string. The function output should first output this character string and then the series of numbers.
- A C function (name, e.g., statistics) should be created for the calculation of the mean and the variance of the series of numbers. I.e., the Statistics function calculates the mean and variance. The statistics function must not contain output via printf or the like.
- For the sorting of the series of numbers, a C function (name e.g., sorting) should be created, which among other things has a call parameter for the sorting order (ascending or descending). I.e., the Sort function sorts in ascending or descending order. The Sort function must not contain Output via or the like.

The following applies to the program:

- All variables should be local. Global variables may not be used.
- The fixed number series 4.31.2 2.4 3.5 5.2 9.8 3.1 should be used.
- The number series is to be output with the function Output. The character string for the output function should be Unsorted:. I.e. the output of the function should be: Unsorted: 4.31.2 2.4 etc.
- It is to be calculated with the function Statistics of the mean and the variance of the number series and output in the main program (main function).
- With the Sort function, the number series should be sorted (ascending or descending).
- The sorted number series should be output with the function Output. The character string for the output function should be Sorted in ascending order: or Sorted in descending order: (depending on the sort order). I.e. the Output Of the function should be sorted in ascending order: 1.2 2.4 3.1 etc. or sorted in descending order: 9.8 5.2 4.3 etc.

To test the program:

Hints:

Mean g -4.214 285, variance Var- 6.615 510.

Due to various effects (e.g., calculation accuracy), the last digits in the results may differ.

Sorted in ascending order: 1.2 2.4 3.13.5 4.3 5.2 9.8

Sorted in descending order: 9.8 5.2 4.3 3.5 3.12.41.2

The sum formula can be implemented with a for loop:

float

for 0=0;}

The function pow can be used to calculate the square of the variance:

e.g., for y = a2: y = pow (a, 2);

For the pow function, the header file math.h must be included: *include <math.h>

The bubble sort algorithm can be used for sorting. For the triangle exchange, the data type float or double must be used for the auxiliary variable the sort order can e.g., be controlled with the type of comparison of the two neighboring values v [0 and v [g + Il: > is an order (e.g. ascending) and <the other order (e.g. descending).

The sort order can also be entered by the user, e.g., + for ascending and for descending. Possible solutions: scanf c, & sign); What is important here is the space before% or character = gg!fb (); Include header file [email protected] #include

## Reviews

There are no reviews yet.