2020-05-29 23:23:24 +03:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
2017-04-05 03:23:33 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int *ARRAY = NULL, ARRAY_LENGTH, i, TEMPORARY_ELEMENT, isSorted = 0;
|
|
|
|
float MEAN = 0, VARIANCE = 0, STAND;
|
|
|
|
|
|
|
|
printf("Enter no. for Random Numbers :");
|
|
|
|
scanf("%d", &ARRAY_LENGTH);
|
|
|
|
ARRAY = (int *)realloc(
|
|
|
|
ARRAY,
|
2020-06-28 18:25:37 +03:00
|
|
|
ARRAY_LENGTH * (sizeof(int))); // We allocate the dedicated memory
|
|
|
|
for (i = 0; i < ARRAY_LENGTH; i++) // We generate the random numbers
|
2020-05-29 23:23:24 +03:00
|
|
|
ARRAY[i] = rand() % 100;
|
|
|
|
|
2020-06-28 18:25:37 +03:00
|
|
|
printf("Random Numbers Generated are :\n"); // We display them
|
|
|
|
for (i = 0; i < ARRAY_LENGTH; i++) printf("%d ", ARRAY[i]);
|
2020-05-29 23:23:24 +03:00
|
|
|
|
2020-06-28 18:25:37 +03:00
|
|
|
printf("\nSorted Data: "); // Then we sort it using Bubble Sort..
|
2020-05-29 23:23:24 +03:00
|
|
|
|
|
|
|
while (!isSorted)
|
2020-06-28 18:25:37 +03:00
|
|
|
{ // While our array's not sorted
|
|
|
|
isSorted = 1; // we suppose that it's sorted
|
2020-05-29 23:23:24 +03:00
|
|
|
for (i = 0; i < ARRAY_LENGTH - 1; i++)
|
2020-06-28 18:25:37 +03:00
|
|
|
{ // then for each element of the array
|
2020-05-29 23:23:24 +03:00
|
|
|
if (ARRAY[i] > ARRAY[i + 1])
|
2020-06-28 18:25:37 +03:00
|
|
|
{ // if the two elements aren't sorted
|
|
|
|
isSorted = 0; // it means that the array is not sorted
|
|
|
|
TEMPORARY_ELEMENT = ARRAY[i]; // and we switch these elements
|
|
|
|
// using TEMPORARY_ELEMENT
|
2020-05-29 23:23:24 +03:00
|
|
|
ARRAY[i] = ARRAY[i + 1];
|
|
|
|
ARRAY[i + 1] = TEMPORARY_ELEMENT;
|
2017-04-05 03:23:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-29 23:23:24 +03:00
|
|
|
for (i = 0; i < ARRAY_LENGTH; i++)
|
|
|
|
{
|
|
|
|
printf("%d ", ARRAY[i]);
|
|
|
|
MEAN = MEAN + ARRAY[i];
|
|
|
|
}
|
|
|
|
MEAN = MEAN / (float)ARRAY_LENGTH;
|
2017-04-05 03:23:33 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
for (i = 0; i < ARRAY_LENGTH; i++)
|
|
|
|
VARIANCE = VARIANCE + (pow((ARRAY[i] - MEAN), 2));
|
2017-04-05 03:23:33 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
VARIANCE = VARIANCE / (float)ARRAY_LENGTH;
|
|
|
|
STAND = sqrt(VARIANCE);
|
2017-04-05 03:23:33 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
printf("\n\n- Mean is: %f\n", MEAN);
|
|
|
|
printf("- Variance is: %f\n", VARIANCE);
|
|
|
|
printf("- Standard Deviation is: %f\n", STAND);
|
2017-04-05 03:23:33 +03:00
|
|
|
}
|