Skip to content

Commit

Permalink
lab5, q2 done
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Sep 19, 2024
1 parent 965185e commit 096dd0c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lab5/binom.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#include "binom.hpp"


int main() {

Binom b(10, 0.5);

std::cout << "Q1: Factorials" << std::endl;
for (int i = 0; i < 10; i++) {
std::cout << b.factorial(i) << std::endl;
std::cout << b.factorial(i + 1) << std::endl;
}

std::cout << "Q2 choose" << std::endl;
for (int i = 0; i < 10; i++) {
std::cout << b.choose(10, i + 1) << std::endl;

}

return 0;
Expand Down
18 changes: 17 additions & 1 deletion lab5/binom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,23 @@ class Binom {


inline int Binom::factorial(int n) const {
return n;

if (n <= 1)
return 1;

return this->factorial(n - 1) * n;

}

inline double Binom::choose(int a, int b) const {

// double a_dbl = (double) a;
// double b_dbl = static_cast<double>(b);

return this->factorial(a)/(
factorial(a - b) * factorial(b)
);

}

#endif

0 comments on commit 096dd0c

Please sign in to comment.