forked from TheAlgorithms/C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mean.c
41 lines (34 loc) · 748 Bytes
/
mean.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX_LEN INT_MAX
int main(int argc, char **argv)
{
int *a, n = 10, i, j, temp, sum = 0;
float mean;
if (argc == 2)
{
n = atoi(argv[1]);
if (n >= MAX_LEN)
{
fprintf(stderr, "Maximum %d!\n", MAX_LEN);
return 1;
}
a = (int *)malloc(n * sizeof(int));
}
printf("Random Numbers Generated are : ");
for (i = 0; i < n; i++)
{
a[i] = rand() % 100;
printf("%2d, ", a[i]);
}
putchar('\n');
for (i = 0; i < n; i++)
sum = sum + a[i];
mean = sum / (float)n;
printf("\nMean :");
printf("%f", mean);
free(a);
return 0;
}