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

Kelly Manahan #2

Open
wants to merge 7 commits into
base: master
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
30 changes: 28 additions & 2 deletions fizzbuzz/fizzbuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,36 @@
by both 3 and 5, print "FizzBuzz". Increment the counter variable
every time that nothing gets printed and return the counter.
Don't forget to include newlines '\n' in your printf statements!

javascript:
for (var i=1; i <= n; i++){
if (i % 15 == 0) console.log("FizzBuzz");
else if (i % 3 == 0) console.log("Fizz");
else if (i % 5 == 0) console.log("Buzz");
else console.log(i);
}

*/
int fizzbuzz(int n)
{

{ int counter = 0;
for( int i = 1; i <=n; i++) {
if (i % 15 == 0)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but it would be better if the instructions for the program told what to do if it was divisible by 3 and divisible by 5...that way in the grand scheme of things....it's only looking for numbers that are divisible by 3 and 5...not 3, 5 and 15.

if(i % 3 == 0 && i % 5 == 0){
            printf("Fizzbuzz \n");
        }

{
printf("FizzBuzz\n");
}
else if (i % 3 == 0)
{
printf("Fizz\n");
}
else if (i % 5 == 0)
{
printf("Buzz\n");
}
else {
counter ++;
}
}
return counter;
}

#ifndef TESTING
Expand Down
17 changes: 15 additions & 2 deletions malloc/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
*/
char *string_dup(char *src)
{

char *dup = malloc(string_length(src));
char *point = dup;
while (*src != '\0') {
*dup = *src;
src++;
dup++;
}
*dup = '\0';
return point;
}

/*
Expand Down Expand Up @@ -43,7 +51,12 @@ void *mem_copy(void *dest, const void *src, int n)
*/
void *resize_memory(void *ptr, int old_size, int new_size)
{

char *pointer = (char *)ptr;
char *old = (char *)old_size;
for (int i = 0; i < new_size; i++) {
*(pointer + i) = *(old + i);
}
return ptr;
}

#ifndef TESTING
Expand Down
13 changes: 10 additions & 3 deletions pointers/pointers.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/
void swap(int* a, int* b)
{

int temp = *a;
*a = *b;
b = temp;
}

/*
Expand All @@ -34,7 +36,12 @@ char *find_char(char *str, int c)
*/
void string_copy(char *x, char *y)
{

while (*y != '\0') {
*x = y;
x++;
y++;
}
*x ='\0';
}

/*
Expand All @@ -53,7 +60,7 @@ void string_copy(char *x, char *y)
*/
int string_compare(char *m, char *n)
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No code here for string_compare. Other stuff looks good. Try string_compare!

}

/*
Expand Down
29 changes: 27 additions & 2 deletions quicksort/quicksort.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,35 @@
*/
void quicksort(int *arr, int low, int high)
{
int i, j, pivot, temp;

if(low < high){
pivot=low;
i = low;
j = high;

while(i<j) {
while (arr[i] <= arr[pivot] && i < high)
i++;
while( arr[j] > arr[pivot])
j--;
if(i<j) {
temp=arr[i];
arr[i] = arr[j];
arr[j]=temp;
}
}

temp = arr[pivot];
arr[pivot] = arr[j];
arr[j] = temp;
quicksort(arr, low, j - 1);
quicksort(arr, j + 1, high);
}

}

#ifndef TESTING
// #ifndef TESTING
int main(void)
{
int arr1[] = {100, 55, 4, 98, 10, 18, 90, 95, 43, 11, 47, 67, 89, 42, 49, 79};
Expand All @@ -35,4 +60,4 @@ int main(void)

return 0;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested. works. great job!

#endif
// #endif
21 changes: 18 additions & 3 deletions strings/strings.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>


/*
Given a character array s, return the number of characters
held inside it.
Expand All @@ -9,9 +10,15 @@
*/
int string_length(char s[])
{

int len = 0;
for(int i = 0; s[i] != '\0'; i++ )
{
len++;
}
return len;
// return printf("%d", len);
// return printf("%c", s[0]);
}

/*
Write a function that reverses the order of string s and outputs
the reversed string to the input array rv. The rv array will have
Expand All @@ -20,7 +27,15 @@ int string_length(char s[])
*/
char *reverse_string(char rv[], char s[])
{

int rvlen = string_length(s);
int arr = 0;
int i;
for (i= (rvlen -1); i>=0; i--) {
rv[arr] = s[i];
arr++;
}
rv[rvlen] ='\0';
return rv;
}

#ifndef TESTING

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. tested.

Expand Down
19 changes: 17 additions & 2 deletions structs/structs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
Person should have the fields `name`, `age`, `height`, and `weight`.
*/
typedef struct Person {

char *name;
int age;
int height;
int weight
} Person;


/*
Creates an instance of the Person struct that receives all the relevant
pieces of data associated with a Person instance.
Expand All @@ -21,7 +25,13 @@ typedef struct Person {
*/
Person *createPerson(char *name, int age, int height, int weight)
{
Person *p = malloc(sizeof(Person));
p->name = string_dup(name);
p->age =age;
p->height = height;
p->weight = weight;

return p;
}

/*
Expand All @@ -30,7 +40,12 @@ Person *createPerson(char *name, int age, int height, int weight)
*/
void destroyPerson(Person *who)
{

if (who != NULL) {
if (who -> name !=NULL) {
free(who -> name);
}
free(who);
}
}

#ifndef TESTING

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested. works! great work!

Expand Down
2 changes: 1 addition & 1 deletion structs/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Person *createPerson(char *name, int age, int height, int weight);

void destroyPerson(Person *who);

#endif
#endif