Skip to content
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
9 changes: 9 additions & 0 deletions assignment8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Christopher Liu
1. The output is ABCabc123. I get how the first part will make the arg capital, but the part after q = p + strlen(a) I don’t get.
2. I don’t know what valgrind is, but probably 7?
3. line 20-23 is redundant and reassigns the array I think. Not sure.
line 28

4.
line 14 char *c
line 28 [free(p)]
34 changes: 34 additions & 0 deletions averagestd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Christopher Liu */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
FILE * file_var = fopen("averagestd.txt", "r");
float distance_sum = 0, total = 0;
int conv = 1, count = 0;
while (!feof(file_var))
{
conv = fscanf(file_var, "%*f");
count++;
}
fseek (file_var, 0, SEEK_SET);
float num_list[count];

for (int i = 0; i < count; i++)
{
fscanf(file_var, "%f", &num_list[i]);
total += num_list[i];
}
float avg = total/count;
for (int i = 0; i < count; i++)
{
distance_sum += (float) fabs((avg - num_list[i])*(avg - num_list[i]));
}
float std = sqrt(distance_sum/count);
printf("AVG: %f, TOTAL: %f, COUNT: %d, STD: %f", avg, total, count, std);

fclose(file_var);
}

16 changes: 16 additions & 0 deletions averagestd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
90
80
99.4
102.7
39210.3
30.0
60.4
70.8
99.54
102.3
98.0
97.6
43.5
60.79
70.92
84.3
71 changes: 71 additions & 0 deletions sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* Christopher Liu */
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

void printlist(int * list, int size)
{
printf("LIST: ");
for (int i = 0; i < size; i++)
{
printf("%d ", list[i]);
}
printf("\n");
}

int main()
{
srand(time(NULL));

int size;
printf("NUMBER: ");
scanf("%d", &size);
int* num_list = (int*) malloc(size*sizeof(int));
for (int i = 0; i < size; i++)
{
num_list[i] = rand()%40;
}
int* as_sort = (int*) malloc((size+1)*sizeof(int));
int* de_sort = (int*) malloc((size+1)*sizeof(int));
for (int i = 0; i < size; i++)
{
as_sort[i] = num_list[i];
de_sort[i] = num_list[i];
}

for (int i = 1; i < size; i++)
{
int key = as_sort[i];
int j = i-1;
while (key < as_sort[j])
{
as_sort[i] = as_sort[j];
i--;
j--;
}
as_sort[i] = key;
}
for (int i = 1; i < size; i++)
{
int key = de_sort[i];
int j = i-1;
while (key > de_sort[j] && i > 0)
{
de_sort[i] = de_sort[j];
i--;
j--;
}
de_sort[i] = key;
}
printf("NUMLIST: ");
printlist(num_list, size);
printf("AS_SORT: ");
printlist(as_sort, size);
printf("DE_SORT: ");
printlist(de_sort, size);
free(num_list);
free(de_sort);
free(as_sort);

return 0;
}