mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 05:21:49 +03:00
fix: possible segmentation faults in numerical_methods/mean.c
(#805)
* fixed possible segmentation fault Fixed possible segmentation fault when no arg is supplied * Update mean.c various small changes to print statements.
This commit is contained in:
parent
8e03e35c80
commit
28fc15c65b
@ -18,10 +18,11 @@ int main(int argc, char **argv)
|
|||||||
fprintf(stderr, "Maximum %d!\n", MAX_LEN);
|
fprintf(stderr, "Maximum %d!\n", MAX_LEN);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
a = (int *)malloc(n * sizeof(int));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Random Numbers Generated are : ");
|
a = (int *)malloc(n * sizeof(int));
|
||||||
|
|
||||||
|
printf("Random Numbers Generated are: ");
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
a[i] = rand() % 100;
|
a[i] = rand() % 100;
|
||||||
@ -32,8 +33,8 @@ int main(int argc, char **argv)
|
|||||||
for (i = 0; i < n; i++) sum = sum + a[i];
|
for (i = 0; i < n; i++) sum = sum + a[i];
|
||||||
|
|
||||||
mean = sum / (float)n;
|
mean = sum / (float)n;
|
||||||
printf("\nMean :");
|
printf("\nMean: ");
|
||||||
printf("%f", mean);
|
printf("%f\n", mean);
|
||||||
|
|
||||||
free(a);
|
free(a);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user