Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
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

namespace  math
 for IO operations
 

Functions

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

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
63 {
64 test(); // execute the tests
65 return 0;
66}
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
37 {
38 int test_case_1 = math::binomialCoeffSum(2);
39 assert(test_case_1 == 4);
40 std::cout << "Test_case_1 Passed!" << std::endl;
41
42 int test_case_2 = math::binomialCoeffSum(3);
43 assert(test_case_2 == 8);
44 std::cout << "Test_case_2 Passed!" << std::endl;
45
46 int test_case_3 = math::binomialCoeffSum(4);
47 assert(test_case_3 == 16);
48 std::cout << "Test_case_3 Passed!" << std::endl;
49
50 int test_case_4 = math::binomialCoeffSum(5);
51 assert(test_case_4 == 32);
52 std::cout << "Test_case_4 Passed!" << std::endl;
53
54 int test_case_5 = math::binomialCoeffSum(7);
55 assert(test_case_5 == 128);
56 std::cout << "Test_case_5 Passed!" << std::endl;
57}
T endl(T... args)
uint64_t binomialCoeffSum(uint64_t n)
Definition sum_of_binomial_coefficient.cpp:26
Here is the call graph for this function: