diff --git a/Assignment8.txt b/Assignment8.txt new file mode 100644 index 0000000..e0b11fe --- /dev/null +++ b/Assignment8.txt @@ -0,0 +1,10 @@ +Clarke Littlejohn + + +1) Can crash. The output if it was not going to crash would be something like ABC 123 or should ge. + +2) The total amount of bytes lot would be something like 1 or 2. the pointer p gets lost since new memory is allocated then. + +3) Line 26 causes memory leaks + +4)line 14 instead of {0,0}; make it {'0','0'}; line 25 free(p); line 32 free(p); diff --git a/sort.c b/sort.c new file mode 100644 index 0000000..0a9003d --- /dev/null +++ b/sort.c @@ -0,0 +1,89 @@ +//Clarke Littejohn +//Sort +#include +#include +#include +int *asc(int[],int,int[]); +int *dsc(int[],int,int[]); + + +int main(){ + srand(time(0)); + int * array,size,*aAry,*dAry; + //user input + printf("Enter the size of the array: "); + scanf("%d",&size); + //creates arrays sizes + array=(int*) malloc(size*sizeof(int)); + aAry = (int *) malloc(size*sizeof(int)); + dAry = (int *) malloc(size*sizeof(int)); + //gets values for the array + int i=0; + while(i +#include + +int main(){ + + FILE* p=fopen("test.txt","r"); + int terms=0; + int tracker=0; + float j=0; + float xbar=0; + float sum=0; + float mean=0; + while(tracker<5){ + fscanf(p,"%f",&j); + xbar+=j; + terms++; + tracker++; + } + xbar/=terms; + tracker=0; + fclose(p); + p=fopen("test.txt","r"); + while(tracker<5){ + fscanf(p,"%f",&j); + j=j-xbar; + j=pow(j,2); + sum+=j; + tracker++; + + } + terms--; + sum/=terms; + sum = sqrt(sum); + printf("%f\n",sum); + fclose(p); + return 0; +}