sum_of_binomial_coefficient.cpp File Reference

Algorithm to find sum of binomial coefficients of a given positive integer. More...

`#include <cassert>`
`#include <iostream>`
Include dependency graph for sum_of_binomial_coefficient.cpp:

## Namespaces

| math
| for std::vector

## Functions

uint64_t | math::binomialCoeffSum (uint64_t n)
static void | test ()
int | main ()
| Main function. More...

## Detailed Description

Algorithm to find sum of binomial coefficients of a given positive integer.

Given a positive integer n, the task is to find the sum of binomial coefficient i.e nC0 + nC1 + nC2 + ... + nCn-1 + nCn By induction, we can prove that the sum is equal to 2^n

See also
  more on https://en.wikipedia.org/wiki/Binomial_coefficient#Sums_of_the_binomial_coefficients

Author
  muskan0719

## Function Documentation

## main()

int main | ( | void |  | ) |

Main function.

Returns
  0 on exit

{
test(); // execute the tests
return 0;
}
test
static void test()
Definition: sum_of_binomial_coefficient.cpp:37
Here is the call graph for this function:

## test()

static void test | ( |  | ) |

static

Function for testing binomialCoeffSum function. test cases and assert statement.

Returns
  `void`

{
int test_case_1 = math::binomialCoeffSum(2);
assert(test_case_1 == 4);
std::cout << "Test_case_1 Passed!" << std::endl;
int test_case_2 = math::binomialCoeffSum(3);
assert(test_case_2 == 8);
std::cout << "Test_case_2 Passed!" << std::endl;
int test_case_3 = math::binomialCoeffSum(4);
assert(test_case_3 == 16);
std::cout << "Test_case_3 Passed!" << std::endl;
int test_case_4 = math::binomialCoeffSum(5);
assert(test_case_4 == 32);
std::cout << "Test_case_4 Passed!" << std::endl;
int test_case_5 = math::binomialCoeffSum(7);
assert(test_case_5 == 128);
std::cout << "Test_case_5 Passed!" << std::endl;
}
std::cout
std::endl
T endl(T... args)
math::binomialCoeffSum
uint64_t binomialCoeffSum(uint64_t n)
Definition: sum_of_binomial_coefficient.cpp:26
Here is the call graph for this function: