From c3608c3f898f106af9486c40c2715852ae5ab31c Mon Sep 17 00:00:00 2001 From: unlockable Date: Fri, 7 Oct 2022 12:29:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E5=9B=9B=E8=AF=BE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 04/Exercise01.c | 11 +++++++++++ 04/Exercise02.c | 6 ++++++ 04/Exercise03.c | 13 +++++++++++++ 04/Optional.c | 17 +++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 04/Exercise01.c create mode 100644 04/Exercise02.c create mode 100644 04/Exercise03.c create mode 100644 04/Optional.c diff --git a/04/Exercise01.c b/04/Exercise01.c new file mode 100644 index 0000000..0c65076 --- /dev/null +++ b/04/Exercise01.c @@ -0,0 +1,11 @@ +#include +#include + +int main() { + double dx, dy, df_1, df_2; + scanf("%lf %lf", &dx, &dy); + df_1 = (1 / sqrt(2 * 3.14)) * exp(-(dx * dx) / 2); + df_2 = sin(dx*dx + dy*dy) * cos(dx + dy) / 3; + printf("f_1 = %lf, f_2 = %lf", df_1, df_2); + return 0; +} \ No newline at end of file diff --git a/04/Exercise02.c b/04/Exercise02.c new file mode 100644 index 0000000..a6d7c2e --- /dev/null +++ b/04/Exercise02.c @@ -0,0 +1,6 @@ +#include +int main() { + int result, x; + printf("%d", (5 > 3 && 2 || 8 < 4 - !0)); + return 0; +} \ No newline at end of file diff --git a/04/Exercise03.c b/04/Exercise03.c new file mode 100644 index 0000000..b46a7b8 --- /dev/null +++ b/04/Exercise03.c @@ -0,0 +1,13 @@ +#include + +int main() { + int people[3] = {0}; + for (int i = 0; i < 3; i++) { + people[i] = 1; + if ((people[1] == 1 || people[1] == 0) && (people[2] == 1 || people[2] == 0) && (people[2] == 0 || people[2] == 1)) { + printf("%d %d %d\n", people[0], people[1], people[2]); + } + people[i] = 0; + } + return 0; +} \ No newline at end of file diff --git a/04/Optional.c b/04/Optional.c new file mode 100644 index 0000000..0d96068 --- /dev/null +++ b/04/Optional.c @@ -0,0 +1,17 @@ +#include + +int main() { + int chicken[3] = {0}; + for (int chick = 1; chick <= 100; chick++) { + for (int rooster = 1; rooster <= 100 - chick; rooster++) { + int hen = 100 - chick - rooster; + if ((hen > chicken[2]) && (chick*5 + rooster*10 + hen*15 == 1000)) { + chicken[0] = chick; + chicken[1] = rooster; + chicken[2] = hen; + } + } + } + printf("Chick: %d, Rooster: %d, Hen: %d", chicken[0], chicken[1], chicken[2]); + return 0; +} \ No newline at end of file