Browse Source
Merge branch 'master' of https://gitlab.cs.hs-fulda.de/fdai8031/cstools101
remotes/origin/userinput
Merge branch 'master' of https://gitlab.cs.hs-fulda.de/fdai8031/cstools101
remotes/origin/userinput
Laurin
11 months ago
7 changed files with 119 additions and 48 deletions
-
20src/ggT/main.c
-
17src/kgV/kgV.c
-
6src/kgV/kgV.h
-
19src/kgV/main.c
-
1team.md
-
59test/ggT/test_ggT.c
-
45test/kgV/test_kgV.c
@ -0,0 +1,20 @@ |
|||
#include "ggT.h" |
|||
#include "../userinput.h" |
|||
#include <stdio.h> |
|||
|
|||
int main(){ |
|||
|
|||
// Getting user input for the two numbers |
|||
printf("Please add the two numbers you want the ggT of:\n"); |
|||
int firstNum = usergetd("first number: ", 0, NULL); |
|||
int secondNum = usergetd("second number: ", 0, NULL); |
|||
|
|||
// Calculating the ggT of those two numbers |
|||
int result = ggT(firstNum, secondNum); |
|||
|
|||
// Print the result |
|||
printf("The ggT of %d and %d is: %d\n", firstNum, secondNum, result); |
|||
|
|||
return 0; |
|||
} |
|||
|
@ -0,0 +1,17 @@ |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include "ggT.h" |
|||
|
|||
int kgV(int fistNumber, int secondNumber){ |
|||
|
|||
// Case for at least one number is Zero |
|||
if(fistNumber == 0 || secondNumber == 0) return 0; |
|||
|
|||
// Regular case of calculating the kgV |
|||
int kgVResult = fistNumber*secondNumber/ ggT(fistNumber, secondNumber); |
|||
|
|||
// Getting the absolute value of the kgV |
|||
int absoluteKgV = abs(kgVResult); |
|||
|
|||
return absoluteKgV; |
|||
} |
@ -0,0 +1,6 @@ |
|||
#ifndef KGV_H |
|||
#define KGV_H |
|||
|
|||
int kgV(int firstNumber, int secondNumber); |
|||
|
|||
#endif |
@ -0,0 +1,19 @@ |
|||
#include "kgV.h" |
|||
#include "../userinput.h" |
|||
#include <stdio.h> |
|||
|
|||
int main(){ |
|||
|
|||
// User input for the two numbers. No matter of positive or negative |
|||
printf("Please add the two numbers you want the kgV of:\n"); |
|||
int firstNum = usergetd("first number: ", NULL, NULL); |
|||
int secondNum = usergetd("second number: ", NULL, NULL); |
|||
|
|||
// Calculation of the kgV |
|||
int result = kgV(firstNum, secondNum); |
|||
|
|||
// Print the result |
|||
printf("The kgV of %d and %d is: %d\n", firstNum, secondNum, result); |
|||
|
|||
return 0; |
|||
} |
@ -1,5 +1,6 @@ |
|||
- TheUltimateOptimist, fdai8031 |
|||
- cxnnqr, fdai7777 |
|||
- fdai7777, fdai7777 |
|||
- Laurin, fdai7858 |
|||
- fdai7968, fdai7968 |
|||
- Hendrik, fdai7595 |
@ -0,0 +1,45 @@ |
|||
#include "unity.h" |
|||
#include "kgV.h" |
|||
#include "ggT.h" |
|||
|
|||
void setUp(void){} |
|||
void tearDown(void){} |
|||
|
|||
// Tests for common Cases: |
|||
void test_kgVOf8And6(void) { |
|||
TEST_ASSERT_EQUAL_INT(24, kgV(8, 6)); |
|||
} |
|||
|
|||
void test_kgVOf2And17(){ |
|||
TEST_ASSERT_EQUAL_INT(34, kgV(2, 17)); |
|||
} |
|||
|
|||
|
|||
|
|||
// Tests for Cases with Zero in input: |
|||
void test_kgVOfFirstNumberZero(){ |
|||
TEST_ASSERT_EQUAL_INT(0, kgV(0, 5)); |
|||
} |
|||
|
|||
void test_kgVOfSecondNumberZero(){ |
|||
TEST_ASSERT_EQUAL_INT(0, kgV(5, 0)); |
|||
} |
|||
|
|||
void test_kgVOfBothNumbersZero(){ |
|||
TEST_ASSERT_EQUAL_INT(0, kgV(0, 0)); |
|||
} |
|||
|
|||
|
|||
|
|||
// Tests for Cases with negative numbers |
|||
void test_kgVOfFirstNumberNegative(){ |
|||
TEST_ASSERT_EQUAL_INT(34, kgV(-2, 17)); |
|||
} |
|||
|
|||
void test_kgVOfSecondNumberNegative(){ |
|||
TEST_ASSERT_EQUAL_INT(34, kgV(2, -17)); |
|||
} |
|||
|
|||
void test_kgVOfBothNumbersNegative(){ |
|||
TEST_ASSERT_EQUAL_INT(34, kgV(-2, -17)); |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue