diff --git a/c/p11.c b/c/p11.c index d6ef183..264549b 100644 --- a/c/p11.c +++ b/c/p11.c @@ -13,7 +13,8 @@ int isSameTree(struct TreeNode* p, struct TreeNode* q){ return 1; } if(p->val == q->val){ - return isSameTree(p->left, q->left) || isSameTree(p->right, q->right); + if( isSameTree(p->left, q->left) || isSameTree(p->right, q->right)) + return 1; } return 0; } diff --git a/c/p13.c b/c/p13.c index 753cad1..90eeb08 100644 --- a/c/p13.c +++ b/c/p13.c @@ -13,7 +13,7 @@ int main(){ int n = sizeof(a)/sizeof(a[0]); int m = sizeof(b)/sizeof(b[0]); - for(int i=0;i +int x; int *fun() { - int x = 5; + x = 5; return &x; } int main() diff --git a/c/p8.c b/c/p8.c index 5379851..c5f67e9 100644 --- a/c/p8.c +++ b/c/p8.c @@ -5,7 +5,7 @@ float computeAverage(float* x, size_t* N) { float numerator = 0.0; float denominator = 0.0; - for (size_t i = 0; i < (size_t)N; i++) { + for (size_t i = 0; i < (size_t)*N; i++) { numerator += x[i]; denominator++; } diff --git a/c/p9.c b/c/p9.c index 62ae10a..1867648 100644 --- a/c/p9.c +++ b/c/p9.c @@ -9,18 +9,19 @@ */ #include +#include int* filterMultiples(int* arr, int N, int* NOut, int num) { int numPrimes = 0; *NOut = 0; for (int i = 0; i < N; i++) { if (arr[i] >= num && arr[i]%num == 0) { - *NOut++; + (*NOut)++; } } int* multiples = malloc((*NOut)*sizeof(int)); int idx = 0; - for (int i = 0; i < *NOut; i++) { + for (int i = 0; i < N; i++) { if (arr[i] >= num && arr[i]%num == 0) { multiples[idx] = arr[i]; idx++; @@ -33,7 +34,8 @@ int main() { int arr[10] = {5, 6, 12, 20, 18, 24, 48, 58, 60, 68}; // Multiples of 6 int NOut; - int* multiples = filterMultiples(arr, 10, &NOut, 6); + int* multiples = malloc(100*sizeof(int)); + multiples = filterMultiples(arr, 10, &NOut, 6); for (int i = 0; i < NOut; i++) { printf("%i ", multiples[i]); }