A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d8/db1/binomial__calculate_8cpp.html below:

TheAlgorithms/C++: math/binomial_calculate.cpp File Reference

Loading...

Searching...

No Matches

binomial_calculate.cpp File Reference

Program to calculate Binomial coefficients More...

#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <iostream>

Include dependency graph for binomial_calculate.cpp:

Go to the source code of this file.

Functions size_t  math::binomial::calculate (int32_t n, int32_t k)   Function to calculate binomial coefficients.
static void  tests ()   Test implementations.
int  main (int argc, const char *argv[])   Main function.
Detailed Description Function Documentation ◆ 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

Definition at line 32 of file binomial_calculate.cpp.

32 {

33 // basic cases

34 if (k > (n / 2))

35 k = n - k;

36 if (k == 1)

37 return n;

38 if (k == 0)

39 return 1;

40

41 size_t result = 1;

42 for (int32_t i = 1; i <= k; ++i) {

43 result *= n - k + i;

44 result /= i;

45 }

46

47 return result;

48}

◆ main() int main ( int argc, const char * argv[] )

Main function.

Parameters
argc commandline argument count argv commandline array of arguments
Returns
0 on exit

Definition at line 79 of file binomial_calculate.cpp.

79 {

80 tests

();

// run self-test implementations

81

82 if (argc < 3) {

83 std::cout << "Usage ./binomial_calculate {n} {k}" << std::endl;

84 return 0;

85 }

86

87 int32_t n = atoi(argv[1]);

88

int32_t

k

= atoi(argv[2]);

89

91 return 0;

92}

static void tests()

Test implementations.

size_t calculate(int32_t n, int32_t k)

Function to calculate binomial coefficients.

double k(double x)

Another test function.

◆ tests()

Test implementations.

Returns
void

Definition at line 56 of file binomial_calculate.cpp.

56 {

57 // tests for calculate function

68

69 std::cout << "[+] Binomial coefficients calculate test completed"

70 << std::endl;

71}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4