commit 79415e38db57307ef492e557f4fce4c580f20564 Author: Hayet Date: Thu May 28 10:16:10 2026 +0000 Happy About the progress diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f00631a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +libcs50/ +a.out diff --git a/Assembly/asem b/Assembly/asem new file mode 100755 index 0000000..69262cf Binary files /dev/null and b/Assembly/asem differ diff --git a/Assembly/asem.o b/Assembly/asem.o new file mode 100644 index 0000000..71ebe90 Binary files /dev/null and b/Assembly/asem.o differ diff --git a/Assembly/asem.s b/Assembly/asem.s new file mode 100644 index 0000000..c2caa97 --- /dev/null +++ b/Assembly/asem.s @@ -0,0 +1,21 @@ +.global _start +.intel_syntax noprefix + +_start: + // sys_write + mov rax, 1 + mov rdi, 1 + lea rsi, [hello_world] + mov rdx, 14 + syscall + + + // sys_exit + mov rdi, 60 + mov rdi, 69 + syscall + +hello_world: + .asciz "Hello, World!\n" + + diff --git a/Assembly/asenm.o b/Assembly/asenm.o new file mode 100644 index 0000000..1bce3d4 Binary files /dev/null and b/Assembly/asenm.o differ diff --git a/Assembly/readme.txt b/Assembly/readme.txt new file mode 100644 index 0000000..88840f4 --- /dev/null +++ b/Assembly/readme.txt @@ -0,0 +1,11 @@ + +# VIM Notes + +:wq - Save and Exit +:q! - Exit without Saving +:q - Exit only If Unchanged. +:x Quick Save and Exit. + +# Keyboard Shortcuts +ESC - From Normal to a state where you can enter commands. +I = Get into Insert mode. diff --git a/Hayet_Classwork/Programs/agree b/Hayet_Classwork/Programs/agree new file mode 100755 index 0000000..eaa005a Binary files /dev/null and b/Hayet_Classwork/Programs/agree differ diff --git a/Hayet_Classwork/Programs/cat b/Hayet_Classwork/Programs/cat new file mode 100755 index 0000000..74a3fe2 Binary files /dev/null and b/Hayet_Classwork/Programs/cat differ diff --git a/Hayet_Classwork/Programs/compare b/Hayet_Classwork/Programs/compare new file mode 100755 index 0000000..343b0f8 Binary files /dev/null and b/Hayet_Classwork/Programs/compare differ diff --git a/Hayet_Classwork/Programs/hello b/Hayet_Classwork/Programs/hello new file mode 100755 index 0000000..f125449 Binary files /dev/null and b/Hayet_Classwork/Programs/hello differ diff --git a/Hayet_Classwork/agree.c b/Hayet_Classwork/agree.c new file mode 100644 index 0000000..e3aa64f --- /dev/null +++ b/Hayet_Classwork/agree.c @@ -0,0 +1,20 @@ +#include +#include + +int main(void) + +{ + char c = get_char("Do you agree? "); + + if (c == 'y' || c == 'Y') + + { + printf("Agreed.\n"); + + } + + else + { + printf("Not Agreed.'\n"); + } +} \ No newline at end of file diff --git a/Hayet_Classwork/cat.c b/Hayet_Classwork/cat.c new file mode 100644 index 0000000..538e086 --- /dev/null +++ b/Hayet_Classwork/cat.c @@ -0,0 +1,18 @@ +#include +#include +//Proacive Promise for future. +void meow(int tiomes); + +int main (void) +{ + int n = get_int("What's n? "); + meow(n); +} + +void meow(int times) +{ + for (int i = 0; i < times; i++) + { + printf("meow\n"); + } +} \ No newline at end of file diff --git a/Hayet_Classwork/compare.c b/Hayet_Classwork/compare.c new file mode 100644 index 0000000..5707de3 --- /dev/null +++ b/Hayet_Classwork/compare.c @@ -0,0 +1,15 @@ +#include +#include + +int main(void) + +{ + int x = get_int("What's x? "); + int y = get_int("what's y? "); + + if (x < y) + + { + printf("x is greater than y\n"); + } +} diff --git a/Hayet_Classwork/hello.c b/Hayet_Classwork/hello.c new file mode 100644 index 0000000..0288300 --- /dev/null +++ b/Hayet_Classwork/hello.c @@ -0,0 +1,8 @@ +#include +#include + +int main(void) +{ + string answer = get_string("What's your name? "); + printf("Hello, %s\n", answer); +} \ No newline at end of file diff --git a/Hayet_Classwork/notes.txt b/Hayet_Classwork/notes.txt new file mode 100644 index 0000000..f503dbb --- /dev/null +++ b/Hayet_Classwork/notes.txt @@ -0,0 +1,13 @@ +Conditional +If (boolean-expression) +{ + +} + +else + +{ + +} + +// If the boolean-expression evaluates to true , all lines of code between phrases. diff --git a/Hayet_Classwork/struct.c b/Hayet_Classwork/struct.c new file mode 100644 index 0000000..9fa4f8a --- /dev/null +++ b/Hayet_Classwork/struct.c @@ -0,0 +1,39 @@ +#include +#include + +typedef struct +{ + string name; + int votes; + +} candidate; + +candidate get_candidate(void); + +int main(void) +{ + candidate candidates[3]; + + for (int i =0; i <3; i++) + { + candidates[i] = get_candidate(); + } + + for (int i = 0; i < 3; i++) + { + printf("Candidate %i is named %s and has %i votes.\n",i + 1, candidates[i].name, candidates[i].votes); + + } +} + +// Function to get a new candidate + +candidate get_candidate(void) +{ + candidate new_candidate; + new_candidate.name = get_string("Name: ") ; + new_candidate.votes = get_int("Votes:") ; + + return new_candidate; + +} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..66d4513 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +iteration: + clang iteration.c -lcs50 -o iteration diff --git a/a.out b/a.out new file mode 100644 index 0000000..e69de29 diff --git a/buggy b/buggy new file mode 100755 index 0000000..ca3632a Binary files /dev/null and b/buggy differ diff --git a/buggy.c b/buggy.c new file mode 100644 index 0000000..8c2cca4 --- /dev/null +++ b/buggy.c @@ -0,0 +1,8 @@ +#include +#include + +int main(void) +{ + string name = get_string("What's your name> "); + printf("hello, %s\n", name); +} diff --git a/calculator.c b/calculator.c new file mode 100644 index 0000000..594855b --- /dev/null +++ b/calculator.c @@ -0,0 +1,2 @@ +#include +#include diff --git a/cond.c b/cond.c new file mode 100644 index 0000000..ae17606 --- /dev/null +++ b/cond.c @@ -0,0 +1,20 @@ +#include +#include + +{ + int x = get_int(); + switch(x) + { + case 5: + printf("Five, "); + case 4: + printf("Four, "); + case 3: + printf("Three, "); + case 2: + printf("Two, "); + case 1: + printf("One, "); + default: + printf("Blast-off!\n"); + } diff --git a/conditional.c b/conditional.c new file mode 100644 index 0000000..1e5f447 --- /dev/null +++ b/conditional.c @@ -0,0 +1,32 @@ +//Boolean expression. +if (balance < 0) + +{ + printf("Insufficient Funds"); + +} +else +{ + printf("Available Balance"); +} + +//For Loops +for (int i =1; i <=30; i++) +{ + printf("I can count to %i!\n", i); +} + +// While Loops +int i =1; +while (i <= 30) +{ + printf("I can count to %i") + i++; //Direction -> +} + +int n; +{ +n = get_int("N; "); + +} +while (n <= 0); \ No newline at end of file diff --git a/contacts b/contacts new file mode 100755 index 0000000..dc53b9d Binary files /dev/null and b/contacts differ diff --git a/contacts.c b/contacts.c new file mode 100644 index 0000000..f220beb --- /dev/null +++ b/contacts.c @@ -0,0 +1,22 @@ +#include +#include + +int main(void) + +{ + string name = get_string("Name: "); + int age = get_int("Age: " ); + string phone = get_string("Phone number: "); + string location = get_string("what's your location? " ); +// Correct Version of This program is +// int age = get_int("Age: "); +// int phone = get_int("Phone: ")";" +// Location is correct on the above program so its okay. + +// printf("Name:, %s\n", name); +// printf("Age:, %s\n", age); +// printf("Location:, %s\n", location); + + printf("New Contacts: %s, %i, lives in %s, and can be reached at %s\n", name, age, location, phone ); + +} diff --git a/factorial b/factorial new file mode 100755 index 0000000..6475b35 Binary files /dev/null and b/factorial differ diff --git a/factorial.c b/factorial.c new file mode 100644 index 0000000..d5d0ae4 --- /dev/null +++ b/factorial.c @@ -0,0 +1,23 @@ +#include +#include + +int factorial(int n); + +int main(void) +{ + int n = get_int("Factorial of: "); + printf("Factorial of %i is %i\n", n, factorial(n)); + +} + +int factorial(int n) +{ + // Base case + if (n == 0) + { + return 1; + } + + // Recursive case + return n * factorial(n - 1); +} diff --git a/fibonacci b/fibonacci new file mode 100755 index 0000000..a599d4a Binary files /dev/null and b/fibonacci differ diff --git a/fibonacci.c b/fibonacci.c new file mode 100644 index 0000000..7147d7e --- /dev/null +++ b/fibonacci.c @@ -0,0 +1,32 @@ +#include +#include + +int fib(int n); + +int main(void) + +{ + int n = get_int("Fibonacci: "); + printf("The %i Fibonacci number is %i\n", n, fib(n)); +} + + +// Takes which fibonacci number you want, returns that + +int fib(int n) +{ + // Base Case + if (n ==0) + { + return 0; + } + + if (n == 1) + { + return 1; + } + +// Renursive Case + return fib(n-1) + fib(n-2); +} + diff --git a/hello b/hello new file mode 100755 index 0000000..f125449 Binary files /dev/null and b/hello differ diff --git a/hello.c b/hello.c new file mode 100644 index 0000000..088df65 --- /dev/null +++ b/hello.c @@ -0,0 +1,9 @@ +#include +#include + +int main(void) +{ + string name = get_string("What's your name? "); +// %s = percentage i just operator and "s"is for string. + printf("Hello, %s\n", name); +} diff --git a/iteration b/iteration new file mode 100755 index 0000000..1b1dafc Binary files /dev/null and b/iteration differ diff --git a/iteration.c b/iteration.c new file mode 100644 index 0000000..02fcc08 --- /dev/null +++ b/iteration.c @@ -0,0 +1,25 @@ +#include +#include + +// Prototype +void draw(int n); + +int main(void) +{ + int height = get_int("Height: "); + draw (height); + +} +// Prototype now being used. +void draw(int n) +{ + // for each row of pyramid + for (int i = 0; i < n; i++) + { + for (int j = 0; j < i; j++) + { + printf("#"); + } + printf("\n"); + } +} diff --git a/mario b/mario new file mode 100755 index 0000000..243b6da Binary files /dev/null and b/mario differ diff --git a/mario.c b/mario.c new file mode 100644 index 0000000..b4fe412 --- /dev/null +++ b/mario.c @@ -0,0 +1,17 @@ +#include + +int main(void) +{ + const int n = 3; + //for each row + for (int row = 0; row < 10; row++) + { + //for Each Coloumn + for (int column = 0; column < 10; column++) + { + // Print on brick + printf("#"); + } + printf("\n"); + } +} \ No newline at end of file diff --git a/marioo b/marioo new file mode 100755 index 0000000..6e977ee Binary files /dev/null and b/marioo differ diff --git a/marioo.c b/marioo.c new file mode 100644 index 0000000..f058adf --- /dev/null +++ b/marioo.c @@ -0,0 +1,30 @@ +#include +#include + +void print_row(int bricks); + +int main(void) +{ + // Prompt user for heing (int) + int height = get_int("Height: "); + + // Print Payramid of that height + for (int i = 0; i <= height; i++) + { + print_row(i + 1); + + //Print row based on height + printf("#"); + printf("\n"); + } + +} +// Given a how many a # to print out, print that number of bricks +void print_row(int bricks) +{ + for (int i = 0; i< bricks; i++) + { + printf("#"); + } + printf("\n"); +} \ No newline at end of file diff --git a/note.txt b/note.txt new file mode 100644 index 0000000..b451de4 --- /dev/null +++ b/note.txt @@ -0,0 +1,22 @@ +# Check Code Server Status +sudo systemctl status code-server@$USER + +# Start the Code Server +sudo systemctl start code-server@$USER + +# Git - Cheat Sheet + +// First Set the Username and Email +git config --global user.name "Hayet" +git config --global user.email "your_email@example.com" + +// +git status +git add. +git commit -m "Happy About the progress" + +// Ignore a specific File +vi .gitignore +- libcs50/ +- a.out + diff --git a/phonebook b/phonebook new file mode 100755 index 0000000..4ce31ca Binary files /dev/null and b/phonebook differ diff --git a/phonebook.c b/phonebook.c new file mode 100644 index 0000000..4f15380 --- /dev/null +++ b/phonebook.c @@ -0,0 +1,39 @@ +#include +#include +#include + +typedef struct + +{ + string name; + string number; + +} person; + +int main(void) + +{ + person people[3]; + + people[0].name = ""Kelly"; + people[0].number = "+091398023890123"; + + people[1].name = "Hayet"; + people[1].number = "77666327"; + + people [2].name ="Munna"; + people[2].number ="59950786"; + + string name = get_string("Name: "); + for (int i = 0 ; i < 3; i++) + + { + if (strcmp(people[i].name, name) == 0) + { + printf("Found %s\n", people[i].number); + return 0; + } + } + printf("Not fouind \n"); + return 1; +} diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..ed63a6c --- /dev/null +++ b/readme.txt @@ -0,0 +1,25 @@ +nano hello.c + +#----------------- Program ------------------- + +#include + +int main(void) +{ + printf("Hello, world!\n"); +} + + +# ----------- End ------------------------ + +# Compilation +gcc hello.c -o hello# + +./hello + +# ------------------------------------------- +Important Bookmarks + +https://cs50.harvard.edu/x/notes/1/#header-files-and-cs50-manual-pages +https://manual.cs50.io/ + diff --git a/recursion b/recursion new file mode 100755 index 0000000..66d11cc Binary files /dev/null and b/recursion differ diff --git a/recursion.c b/recursion.c new file mode 100644 index 0000000..2627b4a --- /dev/null +++ b/recursion.c @@ -0,0 +1,31 @@ +#include +#include + +void draw(int n); + +int main(void) + +{ + int height = get_int("Height; "); + + draw(height); +} + +void draw(int n) +{ + // Base case, making sure loop has exit condition. + if (n <= 0) + { + return; + } + + // Print a pyramid of height n -1 + draw (n-1); + + // Print one more row + for (int i =0; i < n; i++) + { + printf("#"); + } + printf("\n"); +} diff --git a/search b/search new file mode 100755 index 0000000..6588d41 Binary files /dev/null and b/search differ diff --git a/search.c b/search.c new file mode 100644 index 0000000..9f5a9b2 --- /dev/null +++ b/search.c @@ -0,0 +1,20 @@ +#include +#include + +int main (void) + +{ + int numbers[] = {20, 500, 10, 5, 100, 1, 50}; + + int n = get_int("Number: "); + for (int i = 0; i < 7; i++) + { + if (numbers[i] == n) + { + printf("Found\n"); + return 0; + } + } + printf("Not found\n"); + return 1; +} diff --git a/src1/agree0.c b/src1/agree0.c new file mode 100644 index 0000000..cc68b1c --- /dev/null +++ b/src1/agree0.c @@ -0,0 +1,20 @@ +// Comparing against lowercase char + +#include +#include + +int main(void) +{ + // Prompt user to agree + char c = get_char("Do you agree? "); + + // Check whether agreed + if (c == 'y') + { + printf("Agreed.\n"); + } + else if (c == 'n') + { + printf("Not agreed.\n"); + } +} diff --git a/src1/agree1.c b/src1/agree1.c new file mode 100644 index 0000000..3d2dba1 --- /dev/null +++ b/src1/agree1.c @@ -0,0 +1,24 @@ +// Comparing against lowercase and uppercase char + +#include +#include + +int main(void) +{ + // Prompt user to agree + char c = get_char("Do you agree? "); + + // Check whether agreed + if (c == 'y') + { + printf("Agreed.\n"); + } + else if (c == 'Y') + { + printf("Agreed.\n"); + } + else + { + printf("Not agreed.\n"); + } +} diff --git a/src1/agree2.c b/src1/agree2.c new file mode 100644 index 0000000..9cb39e5 --- /dev/null +++ b/src1/agree2.c @@ -0,0 +1,20 @@ +// Logical operators + +#include +#include + +int main(void) +{ + // Prompt user to agree + char c = get_char("Do you agree? "); + + // Check whether agreed + if (c == 'Y' || c == 'y') + { + printf("Agreed.\n"); + } + else + { + printf("Not agreed.\n"); + } +} diff --git a/src1/calculator0.c b/src1/calculator0.c new file mode 100644 index 0000000..235d4b1 --- /dev/null +++ b/src1/calculator0.c @@ -0,0 +1,19 @@ +// Addition with int + +#include +#include + +int main(void) +{ + // Prompt user for x + int x = get_int("What's x? "); + + // Prompt user for y + int y = get_int("What's y? "); + + // Add numbers + int z = x + y; + + // Perform addition + printf("%i\n", z); +} diff --git a/src1/calculator1.c b/src1/calculator1.c new file mode 100644 index 0000000..71d2155 --- /dev/null +++ b/src1/calculator1.c @@ -0,0 +1,16 @@ +// Addition with int, without third variable + +#include +#include + +int main(void) +{ + // Prompt user for x + int x = get_int("What's x? "); + + // Prompt user for y + int y = get_int("What's y? "); + + // Perform addition + printf("%i\n", x + y); +} diff --git a/src1/calculator2.c b/src1/calculator2.c new file mode 100644 index 0000000..72d8870 --- /dev/null +++ b/src1/calculator2.c @@ -0,0 +1,13 @@ +// Doubles a number + +#include +#include + +int main(void) +{ + // Prompt user for x + int x = get_int("What's x? "); + + // Double it + printf("%i\n", x * 2); +} diff --git a/src1/calculator3.c b/src1/calculator3.c new file mode 100644 index 0000000..b616b5a --- /dev/null +++ b/src1/calculator3.c @@ -0,0 +1,22 @@ +// Overflow + +#include +#include + +int main(void) +{ + int dollars = 1; + while (true) + { + char c = get_char("Here's $%i. Double it and give to next person? ", dollars); + if (c == 'y') + { + dollars *= 2; + } + else + { + break; + } + } + printf("Here's $%i.\n", dollars); +} diff --git a/src1/calculator4.c b/src1/calculator4.c new file mode 100644 index 0000000..d629c22 --- /dev/null +++ b/src1/calculator4.c @@ -0,0 +1,22 @@ +// long + +#include +#include + +int main(void) +{ + long dollars = 1; + while (true) + { + char c = get_char("Here's $%li. Double it and give to next person? ", dollars); + if (c == 'y') + { + dollars *= 2; + } + else + { + break; + } + } + printf("Here's $%li.\n", dollars); +} diff --git a/src1/calculator5.c b/src1/calculator5.c new file mode 100644 index 0000000..96de636 --- /dev/null +++ b/src1/calculator5.c @@ -0,0 +1,16 @@ +// Division with ints, demonstrating truncation + +#include +#include + +int main(void) +{ + // Prompt user for x + int x = get_int("What's x? "); + + // Prompt user for y + int y = get_int("What's y? "); + + // Divide x by y + printf("%i\n", x / y); +} diff --git a/src1/calculator6.c b/src1/calculator6.c new file mode 100644 index 0000000..b49eeb1 --- /dev/null +++ b/src1/calculator6.c @@ -0,0 +1,16 @@ +// Casting + +#include +#include + +int main(void) +{ + // Prompt user for x + int x = get_int("What's x? "); + + // Prompt user for y + int y = get_int("What's y? "); + + // Divide x by y + printf("%f\n", (float) x / y); +} diff --git a/src1/calculator7.c b/src1/calculator7.c new file mode 100644 index 0000000..925d795 --- /dev/null +++ b/src1/calculator7.c @@ -0,0 +1,16 @@ +// Floats + +#include +#include + +int main(void) +{ + // Prompt user for x + float x = get_float("What's x? "); + + // Prompt user for y + float y = get_float("What's y? "); + + // Divide x by y + printf("%.50f\n", x / y); +} diff --git a/src1/cat0.c b/src1/cat0.c new file mode 100644 index 0000000..457aa39 --- /dev/null +++ b/src1/cat0.c @@ -0,0 +1,10 @@ +// Opportunity for better design + +#include + +int main(void) +{ + printf("meow\n"); + printf("meow\n"); + printf("meow\n"); +} diff --git a/src1/cat1.c b/src1/cat1.c new file mode 100644 index 0000000..d9a63fc --- /dev/null +++ b/src1/cat1.c @@ -0,0 +1,13 @@ +// Better design + +#include + +int main(void) +{ + int i = 3; + while (i > 0) + { + printf("meow\n"); + i--; + } +} diff --git a/src1/cat10.c b/src1/cat10.c new file mode 100644 index 0000000..b9fd989 --- /dev/null +++ b/src1/cat10.c @@ -0,0 +1,19 @@ +// Uses a do-while loop instead. + +#include +#include + +int main(void) +{ + int n; + do + { + n = get_int("What's n? "); + } + while (n < 0); + + for (int i = 0; i < n; i++) + { + printf("meow\n"); + } +} diff --git a/src1/cat11.c b/src1/cat11.c new file mode 100644 index 0000000..d118657 --- /dev/null +++ b/src1/cat11.c @@ -0,0 +1,19 @@ +// Abstraction + +#include + +void meow(void); + +int main(void) +{ + for (int i = 0; i < 3; i++) + { + meow(); + } +} + +// Meow once +void meow(void) +{ + printf("meow\n"); +} diff --git a/src1/cat12.c b/src1/cat12.c new file mode 100644 index 0000000..4a3d500 --- /dev/null +++ b/src1/cat12.c @@ -0,0 +1,19 @@ +// Abstraction with parameterization + +#include + +void meow(int n); + +int main(void) +{ + meow(3); +} + +// Meow some number of times +void meow(int n) +{ + for (int i = 0; i < n; i++) + { + printf("meow\n"); + } +} diff --git a/src1/cat13.c b/src1/cat13.c new file mode 100644 index 0000000..e8fea6e --- /dev/null +++ b/src1/cat13.c @@ -0,0 +1,20 @@ +// Demonstrates scope + +#include + +void meow(int n); + +int main(void) +{ + int n = 3; + meow(n); +} + +// Meow some number of times +void meow(int n) +{ + for (int i = 0; i < n; i++) + { + printf("meow\n"); + } +} diff --git a/src1/cat14.c b/src1/cat14.c new file mode 100644 index 0000000..2427fe7 --- /dev/null +++ b/src1/cat14.c @@ -0,0 +1,26 @@ +// User input + +#include +#include + +void meow(int n); + +int main(void) +{ + int n; + do + { + n = get_int("Number: "); + } + while (n < 1); + meow(n); +} + +// Meow some number of times +void meow(int n) +{ + for (int i = 0; i < n; i++) + { + printf("meow\n"); + } +} diff --git a/src1/cat15.c b/src1/cat15.c new file mode 100644 index 0000000..68527d3 --- /dev/null +++ b/src1/cat15.c @@ -0,0 +1,34 @@ +// Return value + +#include +#include + +int get_positive_int(void); +void meow(int n); + +int main(void) +{ + int n = get_positive_int(); + meow(n); +} + +// Get number of meows +int get_positive_int(void) +{ + int n; + do + { + n = get_int("Number: "); + } + while (n < 1); + return n; +} + +// Meow some number of times +void meow(int n) +{ + for (int i = 0; i < n; i++) + { + printf("meow\n"); + } +} diff --git a/src1/cat2.c b/src1/cat2.c new file mode 100644 index 0000000..8aa91e1 --- /dev/null +++ b/src1/cat2.c @@ -0,0 +1,13 @@ +// Print values of i + +#include + +int main(void) +{ + int i = 1; + while (i <= 3) + { + printf("meow\n"); + i++; + } +} diff --git a/src1/cat3.c b/src1/cat3.c new file mode 100644 index 0000000..88ce846 --- /dev/null +++ b/src1/cat3.c @@ -0,0 +1,13 @@ +// Better design + +#include + +int main(void) +{ + int i = 0; + while (i < 3) + { + printf("meow\n"); + i++; + } +} diff --git a/src1/cat4.c b/src1/cat4.c new file mode 100644 index 0000000..023f307 --- /dev/null +++ b/src1/cat4.c @@ -0,0 +1,11 @@ +// Better design + +#include + +int main(void) +{ + for (int i = 0; i < 3; i++) + { + printf("meow\n"); + } +} diff --git a/src1/cat5.c b/src1/cat5.c new file mode 100644 index 0000000..7ca7dbc --- /dev/null +++ b/src1/cat5.c @@ -0,0 +1,12 @@ +// Infinite loop + +#include +#include + +int main(void) +{ + while (true) + { + printf("meow\n"); + } +} diff --git a/src1/cat6.c b/src1/cat6.c new file mode 100644 index 0000000..1afc1e3 --- /dev/null +++ b/src1/cat6.c @@ -0,0 +1,14 @@ +// Prompts user for n. + +#include +#include + +int main(void) +{ + int n = get_int("What's n? "); + + for (int i = 0; i < n; i++) + { + printf("meow\n"); + } +} diff --git a/src1/cat7.c b/src1/cat7.c new file mode 100644 index 0000000..a0dcb29 --- /dev/null +++ b/src1/cat7.c @@ -0,0 +1,18 @@ +// Prompts user again if need be. (Poor design.) + +#include +#include + +int main(void) +{ + int n = get_int("What's n? "); + if (n < 0) + { + n = get_int("What's n? "); + } + + for (int i = 0; i < n; i++) + { + printf("meow\n"); + } +} diff --git a/src1/cat8.c b/src1/cat8.c new file mode 100644 index 0000000..8636407 --- /dev/null +++ b/src1/cat8.c @@ -0,0 +1,26 @@ +// Uses a loop with continue/break. + +#include +#include + +int main(void) +{ + int n; + while (true) + { + n = get_int("What's n? "); + if (n < 0) + { + continue; + } + else + { + break; + } + } + + for (int i = 0; i < n; i++) + { + printf("meow\n"); + } +} diff --git a/src1/cat9.c b/src1/cat9.c new file mode 100644 index 0000000..d6aa040 --- /dev/null +++ b/src1/cat9.c @@ -0,0 +1,22 @@ +// Uses a loop with just break. + +#include +#include + +int main(void) +{ + int n; + while (true) + { + n = get_int("What's n? "); + if (n >= 0) + { + break; + } + } + + for (int i = 0; i < n; i++) + { + printf("meow\n"); + } +} diff --git a/src1/compare0.c b/src1/compare0.c new file mode 100644 index 0000000..e63f8bd --- /dev/null +++ b/src1/compare0.c @@ -0,0 +1,17 @@ +// Conditional, Boolean expression, relational operator + +#include +#include + +int main(void) +{ + // Prompt user for integers + int x = get_int("What's x? "); + int y = get_int("What's y? "); + + // Compare integers + if (x < y) + { + printf("x is less than y\n"); + } +} diff --git a/src1/compare1.c b/src1/compare1.c new file mode 100644 index 0000000..da4cab0 --- /dev/null +++ b/src1/compare1.c @@ -0,0 +1,21 @@ +// Conditionals that are mutually exclusive + +#include +#include + +int main(void) +{ + // Prompt user for integers + int x = get_int("What's x? "); + int y = get_int("What's y? "); + + // Compare integers + if (x < y) + { + printf("x is less than y\n"); + } + else + { + printf("x is not less than y\n"); + } +} diff --git a/src1/compare2.c b/src1/compare2.c new file mode 100644 index 0000000..e231320 --- /dev/null +++ b/src1/compare2.c @@ -0,0 +1,25 @@ +// Conditionals that aren't mutually exclusive + +#include +#include + +int main(void) +{ + // Prompt user for integers + int x = get_int("What's x? "); + int y = get_int("What's y? "); + + // Compare integers + if (x < y) + { + printf("x is less than y\n"); + } + if (x > y) + { + printf("x is greater than y\n"); + } + if (x == y) + { + printf("x is equal to y\n"); + } +} diff --git a/src1/compare3.c b/src1/compare3.c new file mode 100644 index 0000000..a419964 --- /dev/null +++ b/src1/compare3.c @@ -0,0 +1,25 @@ +// Conditional that isn't necessary + +#include +#include + +int main(void) +{ + // Prompt user for integers + int x = get_int("What's x? "); + int y = get_int("What's y? "); + + // Compare integers + if (x < y) + { + printf("x is less than y\n"); + } + else if (x > y) + { + printf("x is greater than y\n"); + } + else if (x == y) + { + printf("x is equal to y\n"); + } +} diff --git a/src1/compare4.c b/src1/compare4.c new file mode 100644 index 0000000..ddbc2c6 --- /dev/null +++ b/src1/compare4.c @@ -0,0 +1,25 @@ +// Conditionals + +#include +#include + +int main(void) +{ + // Prompt user for integers + int x = get_int("What's x? "); + int y = get_int("What's y? "); + + // Compare integers + if (x < y) + { + printf("x is less than y\n"); + } + else if (x > y) + { + printf("x is greater than y\n"); + } + else + { + printf("x is equal to y\n"); + } +} diff --git a/src1/hello0.c b/src1/hello0.c new file mode 100644 index 0000000..68e40b6 --- /dev/null +++ b/src1/hello0.c @@ -0,0 +1,8 @@ +// A program that says hello to the world + +#include + +int main(void) +{ + printf("hello, world\n"); +} diff --git a/src1/hello1.c b/src1/hello1.c new file mode 100644 index 0000000..0fdfef2 --- /dev/null +++ b/src1/hello1.c @@ -0,0 +1,10 @@ +// get_string and printf with incorrect placeholder + +#include +#include + +int main(void) +{ + string answer = get_string("What's your name? "); + printf("hello, answer\n"); +} diff --git a/src1/hello2.c b/src1/hello2.c new file mode 100644 index 0000000..e55eb61 --- /dev/null +++ b/src1/hello2.c @@ -0,0 +1,10 @@ +// get_string and printf with %s + +#include +#include + +int main(void) +{ + string answer = get_string("What's your name? "); + printf("hello, %s\n", answer); +} diff --git a/src1/mario0.c b/src1/mario0.c new file mode 100644 index 0000000..1aad0c7 --- /dev/null +++ b/src1/mario0.c @@ -0,0 +1,8 @@ +// Prints a row of 4 question marks + +#include + +int main(void) +{ + printf("????\n"); +} diff --git a/src1/mario1.c b/src1/mario1.c new file mode 100644 index 0000000..ef446bc --- /dev/null +++ b/src1/mario1.c @@ -0,0 +1,12 @@ +// Prints a row of 4 question marks with a loop + +#include + +int main(void) +{ + for (int i = 0; i < 4; i++) + { + printf("?"); + } + printf("\n"); +} diff --git a/src1/mario2.c b/src1/mario2.c new file mode 100644 index 0000000..a8b102c --- /dev/null +++ b/src1/mario2.c @@ -0,0 +1,11 @@ +// Prints a column of 3 bricks with a loop + +#include + +int main(void) +{ + for (int i = 0; i < 3; i++) + { + printf("#\n"); + } +} diff --git a/src1/mario3.c b/src1/mario3.c new file mode 100644 index 0000000..97efbad --- /dev/null +++ b/src1/mario3.c @@ -0,0 +1,15 @@ +// Prints a 3-by-3 grid of bricks with nested loops + +#include + +int main(void) +{ + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + printf("#"); + } + printf("\n"); + } +} diff --git a/src1/mario4.c b/src1/mario4.c new file mode 100644 index 0000000..52a664c --- /dev/null +++ b/src1/mario4.c @@ -0,0 +1,16 @@ +// Prints a 3-by-3 grid of bricks with nested loops using a constant + +#include + +int main(void) +{ + const int n = 3; + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + printf("#"); + } + printf("\n"); + } +} diff --git a/src1/mario5.c b/src1/mario5.c new file mode 100644 index 0000000..ab98a35 --- /dev/null +++ b/src1/mario5.c @@ -0,0 +1,23 @@ +// Helper function + +#include + +void print_row(int width); + +int main(void) +{ + const int n = 3; + for (int i = 0; i < n; i++) + { + print_row(n); + } +} + +void print_row(int width) +{ + for (int i = 0; i < width; i++) + { + printf("#"); + } + printf("\n"); +} diff --git a/struct b/struct new file mode 100755 index 0000000..1b5bf01 Binary files /dev/null and b/struct differ diff --git a/struct.c b/struct.c new file mode 100644 index 0000000..1114550 --- /dev/null +++ b/struct.c @@ -0,0 +1,34 @@ +#include +#include + +typedef struct +{ + string name; + int votes; + +} candidate; + +candidate get_candidate(void); + +int main(void) +{ + candidate candidates[3]; + + for (int i =0; i <3; i++) + { + candidates[i] = get_candidate(); + printf("Candidate %i is named %s and has %i votes. \n", i + 1, candidates[i].name, candidates[i].votes); + } +} + +// Function to get a new candidate + +candidate get_candidate(void) +{ + candidate new_candidate; + new_candidate.name = get_string("Name: ") ; + new_candidate.votes = get_int("Votes:") ; + + return new_candidate; + +} diff --git a/struct1.c b/struct1.c new file mode 100644 index 0000000..1114550 --- /dev/null +++ b/struct1.c @@ -0,0 +1,34 @@ +#include +#include + +typedef struct +{ + string name; + int votes; + +} candidate; + +candidate get_candidate(void); + +int main(void) +{ + candidate candidates[3]; + + for (int i =0; i <3; i++) + { + candidates[i] = get_candidate(); + printf("Candidate %i is named %s and has %i votes. \n", i + 1, candidates[i].name, candidates[i].votes); + } +} + +// Function to get a new candidate + +candidate get_candidate(void) +{ + candidate new_candidate; + new_candidate.name = get_string("Name: ") ; + new_candidate.votes = get_int("Votes:") ; + + return new_candidate; + +} diff --git a/text.txt b/text.txt new file mode 100644 index 0000000..e3a071a --- /dev/null +++ b/text.txt @@ -0,0 +1 @@ +Hello This is a just a test diff --git a/v1_search b/v1_search new file mode 100755 index 0000000..8b9dfde Binary files /dev/null and b/v1_search differ diff --git a/v1_search.c b/v1_search.c new file mode 100644 index 0000000..97b8dbd --- /dev/null +++ b/v1_search.c @@ -0,0 +1,32 @@ +#include +#include +#include +int main (void) + +{ + string strings [] = {"battleship", "boot", "cannon", "iron", "thimble", "top hat"}; + + string s = get_string("Strings: "); + for (int i = 0; i < 6; i++) + { + if (strcmp(strings [i], == s) == 0) + { + printf("Found\n"); + return 0; + } + } + printf("Not found \n"); + return 1; + +} + + + + + + + + + + +