Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team Dash #350

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion c/p11.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion c/p13.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<n;i++);{
for(int i=0;i<n;i++){
printf("%d ", a[i]);
}
printf("\n");
Expand Down
1 change: 1 addition & 0 deletions c/p14.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ int romanToInt(char * s){
for(int i=0;i<strlen(s)-1;i++){
if(a[i] < a[i+1]){
a[i+1] -= a[i];
a[i] = 0;
}
num += a[i];
}
Expand Down
2 changes: 1 addition & 1 deletion c/p5.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ void main(){
int a=10;
int *ptr = &a;

*ptr++;
(*ptr)++;
printf("%d", *ptr);
}
3 changes: 2 additions & 1 deletion c/p6.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//allocating memory to a pointer through a function

#include<stdio.h>
int x;
int *fun()
{
int x = 5;
x = 5;
return &x;
}
int main()
Expand Down
2 changes: 1 addition & 1 deletion c/p8.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
8 changes: 5 additions & 3 deletions c/p9.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
*/

#include <stdio.h>
#include <stdlib.h>

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++;
Expand All @@ -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]);
}
Expand Down