c-programming

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 0fc9652907d06f18b6243cdfff7e9534dafb39cd
parent 70ee4ecf0f2cf358417289c00aa36ed940d96870
Author: Andrew Laack <andrew@laack.co>
Date:   Sun, 12 Oct 2025 13:04:08 -0500

Did some stuff in c w/ DSA and basic c stuff

Diffstat:
Ac-book/ch1/fahrenheit.c | 15+++++++++++++++
Ac-book/ch1/hello.c | 6++++++
Ac-book/ch1/max-int-size.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adsa/bst.c | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 144 insertions(+), 0 deletions(-)

diff --git a/c-book/ch1/fahrenheit.c b/c-book/ch1/fahrenheit.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int main(){ + + // C = (5/9)(F - 32) + + int step = 10; + + for (int i = 0 ; i <= 10; ++i){ + int f = i * step; + printf("%d\t", f); + float c = (((float) f - 32) * 5 ) / 9; + printf("%f\n", c); + } +} diff --git a/c-book/ch1/hello.c b/c-book/ch1/hello.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main(){ + printf("H\bH\bHell\blo Wo\borld\bd\n"); + return 0; +} diff --git a/c-book/ch1/max-int-size.c b/c-book/ch1/max-int-size.c @@ -0,0 +1,54 @@ +#include <stdio.h> + +// This weirdness is why you might use stdint +// size(long long) == size(long) is weird + +int printSigned(){ + signed int current, prior; + + prior = 0; + current = 1; + + while(current > prior){ + prior = current; + current += 1; + } + + printf("Signed: %d to ", current); + printf("%d\n", prior); + return 0; +} +int printUnsigned(){ + + unsigned int prior = 0; + unsigned int current = 1; + + while(current > prior){ + prior = current; + current += 1; + } + + printf("Unsigned: %u to ", current); + printf("%u\n", prior); + return 0; +} + + +int main(){ + printSigned(); + printUnsigned(); + int nt; + float ft; + double db; + short sh; + long ln; + long long int lnln; + long double lndb; + printf("Int size is %u bytes\n", sizeof(nt)); + printf("Float size is %u bytes\n", sizeof(ft)); + printf("Double size is %u bytes\n", sizeof(db)); + printf("Short size is %u bytes\n", sizeof(sh)); + printf("Long size is %u bytes\n", sizeof(ln)); + printf("Long Long size is %u bytes\n", sizeof(lnln)); + printf("Long Double size is %u bytes\n", sizeof(lndb)); +} diff --git a/dsa/bst.c b/dsa/bst.c @@ -0,0 +1,69 @@ +#include <stdio.h> +#include <stdlib.h> + +struct Node{ + int data; + struct Node* left; + struct Node* right; +}; + +struct Node* initNode(int data){ + struct Node *node = malloc(sizeof(struct Node)); + node->data = data; + node->right = NULL; + node->left = NULL; + return node; +} +void insert(struct Node* nd, int data){ + if(nd->data < data){ + if(nd->left != NULL){ + insert(nd->left, data); + } + else{ + struct Node* newNode = initNode(data); + nd->left = newNode; + } + } + else{ + if(nd->right != NULL){ + insert(nd->right, data); + } + else{ + struct Node* newNode = initNode(data); + nd->right = newNode; + } + } +} + +void printPostorder(struct Node* nodePtr, int isRoot){ + if(nodePtr->left != NULL){ + printPostorder(nodePtr->left, 0); + } + if(nodePtr->right!= NULL){ + printPostorder(nodePtr->right, 0); + } + if(isRoot == 0){ + printf("%d, ", nodePtr->data, 0); + } + else{ + printf("%d", nodePtr->data); + } +} + + +int main(){ + + struct Node* root = initNode(100); + + int items [] = {10 ,1,2,3,5,34,5543,435,34,543,55,345,353,345,3534,76576,846, -1}; + + for (int i = 0 ; items[i] != -1; ++i){ + printf("%d", items[i]); + insert(root, items[i]); + } + printf("\n"); + printPostorder(root,1); + printf("\n"); + + return 0; +}