diff --git a/src/ProduktSumme.c b/src/ProduktSumme.c new file mode 100644 index 0000000..3b8be64 --- /dev/null +++ b/src/ProduktSumme.c @@ -0,0 +1,47 @@ +// +// Created by Justin Trausch on 06.02.2024. +#include + +// Int produkt +// double Produkt +// Bitshift bei Multiplikation mit 2er Potenzen +// +//6713 * 2^1 +// +// +//6713 << 1 +//6713 * 16 = 2^4 +//6713 << 4 +//2^n +//x << n + + +// Funktion zur Berechnung des Produktsymbols +int berechneProdukt(int start, int ende) { + int produkt = 1; + for (int i = start; i <= ende; i++) { + produkt *= i; + } + for (int j = start; j <= ende; j++) { + for (int k = start; k <= ende; k++) { + for (int g = k; g <= ende; g++){ + produkt *= j + k -g; + } + } + } + return produkt; +} + +int berechneSumme(int start, int ende) { + + if (start > ende) { + return 0; + } + + int summe = 0; + for (int i = start; i <= ende; i++) { + summe += i; + } + + return summe; +} \ No newline at end of file diff --git a/src/ProduktSumme.h b/src/ProduktSumme.h new file mode 100644 index 0000000..f2607b2 --- /dev/null +++ b/src/ProduktSumme.h @@ -0,0 +1,13 @@ +// +// Created by Justin Trausch on 06.02.2024. +// + +#ifndef LINKES_TWIX_PRODUKTSUMME_H +#define LINKES_TWIX_PRODUKTSUMME_H + +int berechneProdukt(int start, int ende); + +int berechneSumme(int start, int ende); + + +#endif //LINKES_TWIX_PRODUKTSUMME_H diff --git a/test/test_ProduktSumme.c b/test/test_ProduktSumme.c new file mode 100644 index 0000000..02fbf05 --- /dev/null +++ b/test/test_ProduktSumme.c @@ -0,0 +1,44 @@ +#ifdef TEST + +#include "unity.h" + +#include "ProduktSumme.h" + + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_produkt_1(void) +{ + int result, expected = 1; + + result = berechneProdukt(1,1); + + TEST_ASSERT_EQUAL_INT(expected, result); +} + +void test_Summe_1(void) +{ + int result, expected = 55; + + result = berechneSumme(1,10); + + TEST_ASSERT_EQUAL_INT(expected, result); +} + +void test_Summe_2(void) +{ + int result, expected = 0; + + result = berechneSumme(5,2); + + TEST_ASSERT_EQUAL_INT(expected, result); +} + + +#endif //TEST