Browse Source

Merge branch 'ProduktSumme' into 'master'

Produkt summe

See merge request fdai7848/Linkes-Twix!8
master
fdai7720 11 months ago
parent
commit
f54f1268fb
  1. 47
      src/ProduktSumme.c
  2. 13
      src/ProduktSumme.h
  3. 44
      test/test_ProduktSumme.c

47
src/ProduktSumme.c

@ -0,0 +1,47 @@
//
// Created by Justin Trausch on 06.02.2024.
#include <stdio.h>
// 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;
}

13
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

44
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
Loading…
Cancel
Save