From 1d200f9534a523d9cf11c14a4cc2ada750f457a2 Mon Sep 17 00:00:00 2001 From: juan Date: Wed, 29 Sep 2021 22:20:05 +0800 Subject: [PATCH] add 5 and 6 --- pset2/5-shopping.c | 23 +++++++++++++++++++++++ pset2/6-triangle.c | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 pset2/5-shopping.c create mode 100644 pset2/6-triangle.c diff --git a/pset2/5-shopping.c b/pset2/5-shopping.c new file mode 100644 index 0000000..1eeccac --- /dev/null +++ b/pset2/5-shopping.c @@ -0,0 +1,23 @@ +#include + +int main(void) { + // add up money + int total = 0, single; + for (int i = 0; i < 4; i++) { + scanf("%i", &single); + total += single; + } + + // evaluate results + if (total >= 40) { + printf("%i", total); + } else if (total >= 30) { + printf("%i", total + 5); + } else if (total >= 20) { + printf("%i", total + 8); + } else { + printf("%i", total + 10); + } + + return 0; +} diff --git a/pset2/6-triangle.c b/pset2/6-triangle.c new file mode 100644 index 0000000..58476ad --- /dev/null +++ b/pset2/6-triangle.c @@ -0,0 +1,18 @@ +#include +#include + +int main(void) { + // Initialize values + int a, b, c; + scanf("%i %i %i", &a, &b, &c); + + // Calculate S and area's 2 power + double s = (a + b + c) / (double)2; + double area = (s * (s - a) * (s - b) * (s - c)); + + // Print answer + (area > 0) ? printf("%.3lf", sqrt(area)) + : printf("The edges cannot make up of a triangle."); + + return 0; +}