From a2682d25c6cd0e069ff73a43df74c17a63caabac Mon Sep 17 00:00:00 2001 From: Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> Date: Sat, 17 Feb 2024 22:59:23 +0000 Subject: Sat, Feb 17, 2024, 2:59 PM -08:00 --- wk1/lab/population.c | 25 ++++++++++++++++ wk1/lab1/population.c | 25 ---------------- wk1/pset/cash/cash.c | 70 ++++++++++++++++++++++++++++++++++++++++++++ wk1/pset/hello.c | 8 +++++ wk1/pset/mario-more/mario.c | 55 ++++++++++++++++++++++++++++++++++ wk1/pset1/cash/cash.c | 70 -------------------------------------------- wk1/pset1/hello.c | 8 ----- wk1/pset1/mario-more/mario.c | 55 ---------------------------------- 8 files changed, 158 insertions(+), 158 deletions(-) create mode 100644 wk1/lab/population.c delete mode 100644 wk1/lab1/population.c create mode 100644 wk1/pset/cash/cash.c create mode 100644 wk1/pset/hello.c create mode 100644 wk1/pset/mario-more/mario.c delete mode 100644 wk1/pset1/cash/cash.c delete mode 100644 wk1/pset1/hello.c delete mode 100644 wk1/pset1/mario-more/mario.c (limited to 'wk1') diff --git a/wk1/lab/population.c b/wk1/lab/population.c new file mode 100644 index 0000000..0ade623 --- /dev/null +++ b/wk1/lab/population.c @@ -0,0 +1,25 @@ +#include +#include + +int main(void) +{ + int n; + do + { + n = get_int("Start size: "); + } + while (n < 9); + int end; + do + { + end = get_int("End size: "); + } + while (end <= n); + int year = 0; + while (n < end) + { + int c = (float) n + (n / 12); + year++; + } + printf("%d Years: %i\n", n, year); +} diff --git a/wk1/lab1/population.c b/wk1/lab1/population.c deleted file mode 100644 index 0ade623..0000000 --- a/wk1/lab1/population.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -int main(void) -{ - int n; - do - { - n = get_int("Start size: "); - } - while (n < 9); - int end; - do - { - end = get_int("End size: "); - } - while (end <= n); - int year = 0; - while (n < end) - { - int c = (float) n + (n / 12); - year++; - } - printf("%d Years: %i\n", n, year); -} diff --git a/wk1/pset/cash/cash.c b/wk1/pset/cash/cash.c new file mode 100644 index 0000000..13c6889 --- /dev/null +++ b/wk1/pset/cash/cash.c @@ -0,0 +1,70 @@ +#include +#include + +int get_cents(void); +int calculate_quarters(int cents); +int calculate_dimes(int cents); +int calculate_nickels(int cents); +int calculate_pennies(int cents); + +int main(void) +{ + // Ask how many cents the customer is owed + int cents = get_cents(); + + // Calculate the number of quarters to give the customer + int quarters = calculate_quarters(cents); + cents = cents - quarters * 25; + + // Calculate the number of dimes to give the customer + int dimes = calculate_dimes(cents); + cents = cents - dimes * 10; + + // Calculate the number of nickels to give the customer + int nickels = calculate_nickels(cents); + cents = cents - nickels * 5; + + // Calculate the number of pennies to give the customer + int pennies = calculate_pennies(cents); + cents = cents - pennies * 1; + + // Sum coins + int coins = quarters + dimes + nickels + pennies; + + // Print total number of coins to give the customer + printf("%i\n", coins); +} + +int get_cents(void) +{ + int i; + do + { + i = get_int("How many cents? "); + } + while (i < 0); + return i; +} + +int calculate_quarters(int cents) +{ + cents = cents / 25; + return cents; +} + +int calculate_dimes(int cents) +{ + cents = cents / 10; + return cents; +} + +int calculate_nickels(int cents) +{ + cents = cents / 5; + return cents; +} + +int calculate_pennies(int cents) +{ + return cents; +} diff --git a/wk1/pset/hello.c b/wk1/pset/hello.c new file mode 100644 index 0000000..d840466 --- /dev/null +++ b/wk1/pset/hello.c @@ -0,0 +1,8 @@ +#include +#include + +int main(void) +{ + string name = get_string("What's your first name? "); + printf("Hello, %s\n", name); +} diff --git a/wk1/pset/mario-more/mario.c b/wk1/pset/mario-more/mario.c new file mode 100644 index 0000000..b6f6226 --- /dev/null +++ b/wk1/pset/mario-more/mario.c @@ -0,0 +1,55 @@ +#include +#include + +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 || n > 8); + return n; +} + +void print_grid(size) +{ + for (int i = 0; i < size; i++) + { + for (int j = 0; j < size; j++) + { + if ((size - (j + i)) > 1) + { + printf(" "); + } + else + { + printf("#"); + } + } + printf(" "); + for (int j = size; j > 0; j--) + { + if ((size - (j + i)) > 0) + { + break; + } + else + { + printf("#"); + } + } + printf("\n"); + } +} diff --git a/wk1/pset1/cash/cash.c b/wk1/pset1/cash/cash.c deleted file mode 100644 index 13c6889..0000000 --- a/wk1/pset1/cash/cash.c +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include - -int get_cents(void); -int calculate_quarters(int cents); -int calculate_dimes(int cents); -int calculate_nickels(int cents); -int calculate_pennies(int cents); - -int main(void) -{ - // Ask how many cents the customer is owed - int cents = get_cents(); - - // Calculate the number of quarters to give the customer - int quarters = calculate_quarters(cents); - cents = cents - quarters * 25; - - // Calculate the number of dimes to give the customer - int dimes = calculate_dimes(cents); - cents = cents - dimes * 10; - - // Calculate the number of nickels to give the customer - int nickels = calculate_nickels(cents); - cents = cents - nickels * 5; - - // Calculate the number of pennies to give the customer - int pennies = calculate_pennies(cents); - cents = cents - pennies * 1; - - // Sum coins - int coins = quarters + dimes + nickels + pennies; - - // Print total number of coins to give the customer - printf("%i\n", coins); -} - -int get_cents(void) -{ - int i; - do - { - i = get_int("How many cents? "); - } - while (i < 0); - return i; -} - -int calculate_quarters(int cents) -{ - cents = cents / 25; - return cents; -} - -int calculate_dimes(int cents) -{ - cents = cents / 10; - return cents; -} - -int calculate_nickels(int cents) -{ - cents = cents / 5; - return cents; -} - -int calculate_pennies(int cents) -{ - return cents; -} diff --git a/wk1/pset1/hello.c b/wk1/pset1/hello.c deleted file mode 100644 index d840466..0000000 --- a/wk1/pset1/hello.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int main(void) -{ - string name = get_string("What's your first name? "); - printf("Hello, %s\n", name); -} diff --git a/wk1/pset1/mario-more/mario.c b/wk1/pset1/mario-more/mario.c deleted file mode 100644 index b6f6226..0000000 --- a/wk1/pset1/mario-more/mario.c +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include - -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 || n > 8); - return n; -} - -void print_grid(size) -{ - for (int i = 0; i < size; i++) - { - for (int j = 0; j < size; j++) - { - if ((size - (j + i)) > 1) - { - printf(" "); - } - else - { - printf("#"); - } - } - printf(" "); - for (int j = size; j > 0; j--) - { - if ((size - (j + i)) > 0) - { - break; - } - else - { - printf("#"); - } - } - printf("\n"); - } -} -- cgit v1.2.3