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
10 changes: 10 additions & 0 deletions assignment8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Olivier Gabison

1. CAN CRASH - It is a char array and the array contains integers, thus not allowing the program to compile.
However, if it did compile, it would print the alphabet.

2. That 52 bytes will be lost.

3. char c[2] = { 0, 0 }; - char array with integers

4. NO CHANGE
44 changes: 44 additions & 0 deletions file.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//Olivier Gabison - Put in the size of the array and it organizes the array in ascending / descending order

#include <stdio.h>
#include <math.h>

int main(){

FILE *files;

files = fopen("file.txt", "r");

int x;
fscanf(files, "%d", &x);
float sum;
float arr[x];
float meanarr[x];

for(int i = 0; i < x; i++){
float y;
fscanf(files, "%f", &y);
sum += y;
arr[i] = y;
}

float mean = sum / x;

for(int i = 0; i < x; i++){
float n1 = (arr[i] - mean) * (arr[i] - mean);
meanarr[i] = n1;
}

float sum2;
for(int i = 0; i < x; i++){
sum2 += meanarr[i];
}

float sum3 = sum2 / x - 1;

float sum4 = sqrt(sum3);

printf("%f\n", sum4);
fclose(files);
return 0;
}
9 changes: 9 additions & 0 deletions file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
8
24.5
23.7
76.7
23.6
742.6
213.6
231.7
123.7
75 changes: 75 additions & 0 deletions sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//Olivier Gabison - Standard Deviation Problem

#include <stdio.h>

int main(){

printf("Please input the size of the array\n");
int size;
scanf("%d", &size);

int arr[size];

for(int i = 0; i < size; i++){
arr[i] = rand() % 50;
}

int *ascend;
int *descend;

ascend = (int*) malloc(sizeof(int) * size);
descend = (int*) malloc(sizeof(int) * size);

//Copying values
for(int i = 0; i < size; i++){
ascend[i] = arr[i];
descend[i] = arr[i];
}

//Ascending Array
for(int i = 0; i < size; i++){
for(int j = i + 1; j < size; j++){
if(ascend[j] < ascend[i]){
int temp = ascend[i];
ascend[i] = ascend[j];
ascend[j] = temp;
}
}
}

//Descending Array
for(int i = 0; i < size; i++){
for(int j = i + 1; j < size; j++){
if(descend[j] > descend[i]){
int temp = descend[i];
descend[i] = descend[j];
descend[j] = temp;
}
}
}

//Printing the 1st Array
for(int i = 0; i < size; i++){
printf("%d, ", arr[i]);
}

printf("\n");

//Printing the 2nd Array
for(int i = 0; i < size; i++){
printf("%d, ", ascend[i]);
}

printf("\n");

//Printing the 3rd Array
for(int i = 0; i < size; i++){
printf("%d, ", descend[i]);
}

printf("\n");

free(ascend);
free(descend);
return 0;
}