2020-05-29 23:23:24 +03:00
|
|
|
#include <limits.h>
|
2020-04-08 02:31:29 +03:00
|
|
|
#include <math.h>
|
2020-05-29 23:23:24 +03:00
|
|
|
#include <stdio.h>
|
2020-04-08 17:08:25 +03:00
|
|
|
#include <stdlib.h>
|
2020-04-08 02:31:29 +03:00
|
|
|
|
|
|
|
#define MAX_LEN INT_MAX
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
2016-10-18 17:17:54 +03:00
|
|
|
{
|
2020-05-29 23:23:24 +03:00
|
|
|
int *a, n = 10, i, j, temp, sum = 0;
|
|
|
|
float mean;
|
2020-04-08 02:31:29 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
if (argc == 2)
|
|
|
|
{
|
|
|
|
n = atoi(argv[1]);
|
|
|
|
if (n >= MAX_LEN)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Maximum %d!\n", MAX_LEN);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2021-02-23 21:36:43 +03:00
|
|
|
|
|
|
|
a = (int *)malloc(n * sizeof(int));
|
2020-04-08 02:31:29 +03:00
|
|
|
|
2021-02-23 21:36:43 +03:00
|
|
|
printf("Random Numbers Generated are: ");
|
2020-05-29 23:23:24 +03:00
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
a[i] = rand() % 100;
|
|
|
|
printf("%2d, ", a[i]);
|
|
|
|
}
|
|
|
|
putchar('\n');
|
2016-10-18 17:17:54 +03:00
|
|
|
|
2020-06-28 18:25:37 +03:00
|
|
|
for (i = 0; i < n; i++) sum = sum + a[i];
|
2016-10-18 17:17:54 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
mean = sum / (float)n;
|
2021-02-23 21:36:43 +03:00
|
|
|
printf("\nMean: ");
|
|
|
|
printf("%f\n", mean);
|
2016-10-18 17:17:54 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
free(a);
|
|
|
|
return 0;
|
2020-04-08 02:31:29 +03:00
|
|
|
}
|