diff --git a/Part2 b/Part2 new file mode 100644 index 0000000..f34b735 --- /dev/null +++ b/Part2 @@ -0,0 +1,13 @@ +Matthew Danielson +7/11/16 +Questions for Part 2 + + +1) It will print usage: a , because the first number is 1, not 3. If that is not the case - but I believe it is - then this code wil print out the address of pointer c, and will continue to print out the addresses of pointer p in the final lines of the code. + +2) 1 byte from the original address of p; all of the other values are not values that are manually and dynamically created, thus they are not memory leaks. + +3) Line 28 + +4) Add before the end of main - line 34 - free(q); + On Line 28, the & operator is necessary to get the address of the pointer; otherwise, this code is not valid. diff --git a/sort.c b/sort.c new file mode 100644 index 0000000..ded4770 --- /dev/null +++ b/sort.c @@ -0,0 +1,47 @@ +/* Matthew Danielson +* 7/11/16 +* sort.c +* Sorts random numbers by ascending and descending order +*/ + +#include +#include +#include +#include +int main(){ + srand(time(NULL)); + printf("How long will your set of numbers be?"); + int length; + scanf("%d", &length); + int *array = (int*) malloc(length*sizeof(int)); + int *ascending = (int*) malloc(length*sizeof(int)); + int *descending = (int*) malloc(length*sizeof(int)); + for(int x = 0; x ascending[y+1]){ + int temp = ascending[y+1]; + ascending[y+1] = ascending[y]; + ascending[y] = temp; + + } + + } + + } + for(int x = 0; x<=length; x++){ + descending[x] = ascending[length-x-1]; + + } + for(int x = 0; x