From e44343ad9cf77ee1f151ac9addf0df016466871d Mon Sep 17 00:00:00 2001 From: Fdai7396 Date: Tue, 7 Feb 2023 16:58:09 +0100 Subject: [PATCH] add dezimal_to_bin --- src/funktion.c | 7 +++++++ src/funktion.h | 1 + src/main.c | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/funktion.c b/src/funktion.c index 5bc9ba4..cace527 100644 --- a/src/funktion.c +++ b/src/funktion.c @@ -275,4 +275,11 @@ int ByOne(int n) { n = orig; } return count; +} +int dezimal_to_bin(int dezimal) { + if (dezimal == 0) { + return 0; + } else { + return (dezimal % 2 + 10 * dezimal_to_bin(dezimal / 2)); + } } \ No newline at end of file diff --git a/src/funktion.h b/src/funktion.h index 44890b8..12affd7 100644 --- a/src/funktion.h +++ b/src/funktion.h @@ -44,5 +44,6 @@ float vPunkt(float x1, float x2, float x3, float z1, float z2, float z3, float p double probability_from_tree(double successful_outcomes, double total_outcomes, double branches); int binomial_coefficient(int n, int k); int ByOne(int n); +int dezimal_to_bin(int dezimal); #endif diff --git a/src/main.c b/src/main.c index 29d6c22..3fb6fd3 100644 --- a/src/main.c +++ b/src/main.c @@ -7,7 +7,7 @@ int main() { double a,b,c,d,h,x1,s1,x2,x3,z1,z2,z3,p1,p2,p3,m,x,y,z; - int n; + int n,dezimal; a = getValue('a'); b = getValue('b'); h = getValue('h'); @@ -208,4 +208,8 @@ int main() n = getValue('X'); ByOne(n); + + printf("Bitte geben sie eine Zahl ein!"); + dezimal = getValue('X'); + dezimal_to_bin(dezimal); }