Browse Source

add dezimal_to_bin

main
Fdai7396 2 years ago
parent
commit
e44343ad9c
  1. 7
      src/funktion.c
  2. 1
      src/funktion.h
  3. 6
      src/main.c

7
src/funktion.c

@ -276,3 +276,10 @@ int ByOne(int n) {
} }
return count; return count;
} }
int dezimal_to_bin(int dezimal) {
if (dezimal == 0) {
return 0;
} else {
return (dezimal % 2 + 10 * dezimal_to_bin(dezimal / 2));
}
}

1
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); double probability_from_tree(double successful_outcomes, double total_outcomes, double branches);
int binomial_coefficient(int n, int k); int binomial_coefficient(int n, int k);
int ByOne(int n); int ByOne(int n);
int dezimal_to_bin(int dezimal);
#endif #endif

6
src/main.c

@ -7,7 +7,7 @@
int main() int main()
{ {
double a,b,c,d,h,x1,s1,x2,x3,z1,z2,z3,p1,p2,p3,m,x,y,z; 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'); a = getValue('a');
b = getValue('b'); b = getValue('b');
h = getValue('h'); h = getValue('h');
@ -208,4 +208,8 @@ int main()
n = getValue('X'); n = getValue('X');
ByOne(n); ByOne(n);
printf("Bitte geben sie eine Zahl ein!");
dezimal = getValue('X');
dezimal_to_bin(dezimal);
} }
Loading…
Cancel
Save