Program to calculate Binomial coefficients
More...
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <iostream>
◆ calculate()
| size_t math::binomial::calculate |
( |
int32_t |
n, |
|
|
int32_t |
k |
|
) |
| |
Function to calculate binomial coefficients.
- Parameters
-
| n | first value |
| k | second value |
- Returns
- binomial coefficient for n and k
42 for (int32_t i = 1; i <= k; ++i) {
uint64_t result(uint64_t n)
Definition: fibonacci_sum.cpp:76
◆ main()
| int main |
( |
int |
argc, |
|
|
const char * |
argv[] |
|
) |
| |
Main function.
- Parameters
-
| argc | commandline argument count |
| argv | commandline array of arguments |
- Returns
- 0 on exit
87 int32_t n =
atoi(argv[1]);
88 int32_t k =
atoi(argv[2]);
static void tests()
Test implementations.
Definition: binomial_calculate.cpp:56
size_t calculate(int32_t n, int32_t k)
Function to calculate binomial coefficients.
Definition: binomial_calculate.cpp:32
◆ tests()
Test implementations.
- Returns
- void
58 assert(math::binomial::calculate(1, 1) == 1);
59 assert(math::binomial::calculate(57, 57) == 1);
60 assert(math::binomial::calculate(6, 3) == 20);
61 assert(math::binomial::calculate(10, 5) == 252);
62 assert(math::binomial::calculate(20, 10) == 184756);
63 assert(math::binomial::calculate(30, 15) == 155117520);
64 assert(math::binomial::calculate(40, 20) == 137846528820);
65 assert(math::binomial::calculate(50, 25) == 126410606437752);
66 assert(math::binomial::calculate(60, 30) == 118264581564861424);
67 assert(math::binomial::calculate(62, 31) == 465428353255261088);
69 std::cout <<
"[+] Binomial coefficients calculate test completed"