From a37210c52a34a78990e720087f3c5fe5e26884f8 Mon Sep 17 00:00:00 2001 From: Fdai7396 Date: Tue, 7 Feb 2023 18:39:56 +0100 Subject: [PATCH] add dreieckFlaeche --- src/funktion.c | 4 ++++ src/funktion.h | 1 + src/main.c | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/src/funktion.c b/src/funktion.c index c03a8e4..15436ad 100644 --- a/src/funktion.c +++ b/src/funktion.c @@ -323,4 +323,8 @@ double kreisFlaeche(double r) { } double kreisUmfang(double r) { return 2 * M_PI * r; +} +double dreieckFlaeche(double a, double b, double c) { + double s = (a + b + c) / 2; + return sqrt(s * (s - a) * (s - b) * (s - c)); } \ No newline at end of file diff --git a/src/funktion.h b/src/funktion.h index 74bce7d..5b06b9a 100644 --- a/src/funktion.h +++ b/src/funktion.h @@ -55,5 +55,6 @@ double prozentsatz(double ein, double prozent); double grundwert(double ein, double prozent); double kreisFlaeche(double r); double kreisUmfang(double r); +double dreieckFlaeche(double a, double b, double c); #endif diff --git a/src/main.c b/src/main.c index b48933b..2eb00cf 100644 --- a/src/main.c +++ b/src/main.c @@ -248,4 +248,11 @@ int main() r = getValue('r'); kreisUmfang(r); + + a = getValue('a'); + b = getValue('b'); + c = getValue('c'); + dreieckFlaeche(a,b,c); + double s = (a + b + c) / 2; + printf("Die Flaeche des Dreiecks betraegt: %f\n", sqrt(s * (s - a) * (s - b) * (s - c))); }