diff --git a/src/funktion.c b/src/funktion.c index 8c3696d..e47421f 100644 --- a/src/funktion.c +++ b/src/funktion.c @@ -264,3 +264,18 @@ int binomial_coefficient(int n, int k) { } return result; } +int ByOne(int n) { + int orig, count = 0; + orig = n; + while (n > 0) { + n = n >> 1 << 1; + if (orig - n == 1) + count++; + orig = n >> 1; + n = orig; + } + orig = count; + n = count; + printf("Das Ergebnis lautet: %d", n); + return count; +} \ No newline at end of file diff --git a/src/funktion.h b/src/funktion.h index 1125b81..44890b8 100644 --- a/src/funktion.h +++ b/src/funktion.h @@ -43,5 +43,6 @@ double Vangle(float x1, float x2, float x3, float z1, float z2, float z3); float vPunkt(float x1, float x2, float x3, float z1, float z2, float z3, float p1, float p2, float p3); double probability_from_tree(double successful_outcomes, double total_outcomes, double branches); int binomial_coefficient(int n, int k); +int ByOne(int n); #endif diff --git a/src/main.c b/src/main.c index 0634d66..29d6c22 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +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; a = getValue('a'); b = getValue('b'); h = getValue('h'); @@ -204,4 +205,7 @@ int main() a = getValue('a'); b = getValue('b') binomial_coefficient(a, b); + + n = getValue('X'); + ByOne(n); }