diff options
Diffstat (limited to 'wk1/lect1')
-rw-r--r-- | wk1/lect1/agree.c | 15 | ||||
-rw-r--r-- | wk1/lect1/ask.c | 10 | ||||
-rw-r--r-- | wk1/lect1/calculator.c | 11 | ||||
-rw-r--r-- | wk1/lect1/compare.c | 21 | ||||
-rw-r--r-- | wk1/lect1/hello.c | 6 | ||||
-rw-r--r-- | wk1/lect1/mario.c | 39 | ||||
-rw-r--r-- | wk1/lect1/meow.c | 11 | ||||
-rw-r--r-- | wk1/lect1/phone-book.c | 10 |
8 files changed, 123 insertions, 0 deletions
diff --git a/wk1/lect1/agree.c b/wk1/lect1/agree.c new file mode 100644 index 0000000..0676cd2 --- /dev/null +++ b/wk1/lect1/agree.c @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <cs50.h> + +int main(void) +{ + char c = get_char("Do you agree? "); + if (c == 'y' || c == 'Y') + { + printf("Agreed.\n"); + } + else if (c == 'n' || c == 'N') + { + printf("Not agreed.\n"); + } +} diff --git a/wk1/lect1/ask.c b/wk1/lect1/ask.c new file mode 100644 index 0000000..39a3910 --- /dev/null +++ b/wk1/lect1/ask.c @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <cs50.h> + +int main(void) +{ + string first = get_string("What's your first name? "); + char middle = get_char("What's your middle INITIAL? "); + string last = get_string("What's your last name? "); + printf("Hello, %s %c %s\n", first, middle, last); +} diff --git a/wk1/lect1/calculator.c b/wk1/lect1/calculator.c new file mode 100644 index 0000000..037436d --- /dev/null +++ b/wk1/lect1/calculator.c @@ -0,0 +1,11 @@ +#include <stdio.h> +#include <cs50.h> + +int main(void) +{ + long x = get_int("x: "); + long y = get_int("y: "); + + double z = (double) x / (double) y; + printf("%.20f\n", z); +} diff --git a/wk1/lect1/compare.c b/wk1/lect1/compare.c new file mode 100644 index 0000000..8511597 --- /dev/null +++ b/wk1/lect1/compare.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <cs50.h> + +int main(void) +{ + int x = get_int("What's x? "); + int y = get_int("What's y? "); + + 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/wk1/lect1/hello.c b/wk1/lect1/hello.c new file mode 100644 index 0000000..927f7b6 --- /dev/null +++ b/wk1/lect1/hello.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main(void) +{ + printf("hello, world\n"); +} diff --git a/wk1/lect1/mario.c b/wk1/lect1/mario.c new file mode 100644 index 0000000..b8b4262 --- /dev/null +++ b/wk1/lect1/mario.c @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <cs50.h> + +int get_size(void); +void print_grid(int size); + +int main(void) +{ + //Get Size of Grid + int size = get_size(); + //Print Grid + print_grid(size); +} + +int get_size(void) +{ + int n; + do + { + n = get_int("Size: "); + } + while (n < 1); + return n; +} + +void print_grid(size) +{ + for (int i = 0; i < size; i++) + { + for (int j = 0; j < size; j++) + { + printf("#"); + } + printf("\n"); + } +} + + + diff --git a/wk1/lect1/meow.c b/wk1/lect1/meow.c new file mode 100644 index 0000000..1f511c8 --- /dev/null +++ b/wk1/lect1/meow.c @@ -0,0 +1,11 @@ +#include <stdio.h> +#include <cs50.h> + +int main(void) +{ + int x = 36; + for (int i = 0; i < x; i++) + { + printf("meow\n"); + } +} diff --git a/wk1/lect1/phone-book.c b/wk1/lect1/phone-book.c new file mode 100644 index 0000000..e37fa2b --- /dev/null +++ b/wk1/lect1/phone-book.c @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <cs50.h> + +int main(void) +{ + string name = get_string("What's your name? "); + int age = get_int("What's your age? "); + string phone = get_string("What's your phone number? "); + printf("Age is %i. Name is %s. Number is %s. \n", age, name, phone); +} |