From 26653397ddaa533f8e5d6f4b851d8326e9267049 Mon Sep 17 00:00:00 2001 From: juan Date: Tue, 28 Sep 2021 19:52:33 +0800 Subject: [PATCH] add bupt homework --- pointers.c | 15 ++++++++++++ pset2/1-basketball.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 pointers.c create mode 100644 pset2/1-basketball.c diff --git a/pointers.c b/pointers.c new file mode 100644 index 0000000..6eda79a --- /dev/null +++ b/pointers.c @@ -0,0 +1,15 @@ +#include +#include + +int main(void) { + // initialize pointer variables + char *str; + char str1[20]; + str = &str1; + + strcpy(str1, str); + printf("%s\n", str1); + printf("%s\n", str1); + printf("%i\n", *str); + return 0; +} diff --git a/pset2/1-basketball.c b/pset2/1-basketball.c new file mode 100644 index 0000000..927820b --- /dev/null +++ b/pset2/1-basketball.c @@ -0,0 +1,55 @@ +#include + +int main(void) { + + // initialize variables + int a, b; + scanf("%i %i", &a, &b); + + // case 1: one team has reached 21 points. and less than 22 points + if (a >= 21 && a <= 22) { + if (b < 21) { + printf("A win"); + return 0; + } else { + printf("error"); + return 0; + } + } + if (b >= 21 && b <= 22) { + if (a < 21) { + printf("B win"); + return 0; + } else { + printf("error"); + return 0; + } + } + + // case 2: one team has more points but less than 21 points. + if (a < 21 && b < 21) { + if (a > b) { + printf("A win"); + return 0; + } else if (a < b) { + printf("B win"); + return 0; + } + } + + // case 3: one team has more points than 22 + if (a > 22 || b > 22) { + printf("error"); + return 0; + } + + // case 4: scores are equal + if (a == b) { + if (a < 21 && b < 21) { + printf("no result"); + return 0; + } + } + + return 0; +}