From 28fc15c65be4fbd7eeca476153aaefadd855f257 Mon Sep 17 00:00:00 2001 From: Satbek Abdyldayev Date: Wed, 24 Feb 2021 00:36:43 +0600 Subject: [PATCH] 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. --- numerical_methods/mean.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/numerical_methods/mean.c b/numerical_methods/mean.c index c37dbbc0..6b18637d 100644 --- a/numerical_methods/mean.c +++ b/numerical_methods/mean.c @@ -18,10 +18,11 @@ int main(int argc, char **argv) fprintf(stderr, "Maximum %d!\n", MAX_LEN); return 1; } - a = (int *)malloc(n * sizeof(int)); } + + a = (int *)malloc(n * sizeof(int)); - printf("Random Numbers Generated are : "); + printf("Random Numbers Generated are: "); for (i = 0; i < n; i++) { a[i] = rand() % 100; @@ -32,8 +33,8 @@ int main(int argc, char **argv) for (i = 0; i < n; i++) sum = sum + a[i]; mean = sum / (float)n; - printf("\nMean :"); - printf("%f", mean); + printf("\nMean: "); + printf("%f\n", mean); free(a); return 0;