From 9451beb9772599fd1de7ba9ebaf89745b6f96f33 Mon Sep 17 00:00:00 2001 From: Krishna Vedala Date: Thu, 23 Apr 2020 20:53:53 -0400 Subject: [PATCH] more mallocs --- project_euler/Problem 26/sol1.c | 2 +- project_euler/Problem 401/sol1.c | 3 ++- sorting/counting_Sort.c | 3 ++- sorting/radix_sort_2.c | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/project_euler/Problem 26/sol1.c b/project_euler/Problem 26/sol1.c index fe2421e1..ae0e44a2 100644 --- a/project_euler/Problem 26/sol1.c +++ b/project_euler/Problem 26/sol1.c @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) unsigned short max_digits = 0, max_idx_number = 0; clock_t start_time = clock(); - unsigned short deno; + short deno; #ifdef _OPENMP #pragma omp for #endif diff --git a/project_euler/Problem 401/sol1.c b/project_euler/Problem 401/sol1.c index b555a3c2..70173b0e 100644 --- a/project_euler/Problem 401/sol1.c +++ b/project_euler/Problem 401/sol1.c @@ -79,7 +79,8 @@ uint64_t sigma2(uint64_t N) **/ uint64_t sigma(uint64_t N) { - uint64_t s, sum = 0, i; + uint64_t s, sum = 0; + int64_t i; #ifdef _OPENMP #pragma omp parallel for reduction(+ \ diff --git a/sorting/counting_Sort.c b/sorting/counting_Sort.c index f1ff6dea..efb159f2 100644 --- a/sorting/counting_Sort.c +++ b/sorting/counting_Sort.c @@ -25,7 +25,7 @@ int main() l = a[i]; } - int b[l + 1]; + int *b = (int *)malloc((l + 1) * sizeof(int)); memset(b, 0, (l + 1) * sizeof(b[0])); for (i = 0; i < n; i++) @@ -44,5 +44,6 @@ int main() } free(a); + free(b); return 0; } diff --git a/sorting/radix_sort_2.c b/sorting/radix_sort_2.c index 0ef5d7b8..1c4e2ad7 100644 --- a/sorting/radix_sort_2.c +++ b/sorting/radix_sort_2.c @@ -20,7 +20,7 @@ int MAX(int *ar, int size) void countSort(int *arr, int n, int place) { int i, freq[range] = {0}; - int output[n]; + int *output = (int *)malloc(n * sizeof(int)); // Store count of occurences in freq[] for (i = 0; i < n; i++) @@ -40,6 +40,7 @@ void countSort(int *arr, int n, int place) // Copy the output array to arr[], so it contains numbers according to the current digit for (i = 0; i < n; i++) arr[i] = output[i]; + free(output); } /*This is where the sorting of the array takes place