From 14c1a7faa14a58198b1ea1b918f9cc6da2a9175c Mon Sep 17 00:00:00 2001 From: muskan0719 <53470969+muskan0719@users.noreply.github.com> Date: Wed, 21 Oct 2020 14:52:55 +0530 Subject: [PATCH] update sum_of_binomial_coefficients --- math/sum_of_binomial_coefficient.cpp | 61 +++++++++++++++++----------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/math/sum_of_binomial_coefficient.cpp b/math/sum_of_binomial_coefficient.cpp index 28052c271..ed772b972 100644 --- a/math/sum_of_binomial_coefficient.cpp +++ b/math/sum_of_binomial_coefficient.cpp @@ -1,17 +1,17 @@ /** * @file - * \@brief Program 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 + * @brief Algorithm to find sum of binomial coefficients of a given positive integer. + * @details 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 - * [https://en.wikipedia.org/wiki/Binomial_coefficient#Sums_of_the_binomial_coefficients] - * @author muskan0719[https://github.com/muskan0719] + * @source https://en.wikipedia.org/wiki/Binomial_coefficient#Sums_of_the_binomial_coefficients + * @author muskan0719 [https://github.com/muskan0719] */ -#include -#include -using namespace std; +#include /// for std::cin and std::cout +#include /// for assert /** + * Function to calculate sum of binomial coefficients * @param n number * @return Sum of binomial coefficients of number */ @@ -20,28 +20,41 @@ int binomialCoeffSum(int n) //Calculating 2^n return (1 << n); } + /** - * Function for testing the binomialCoeffSum() function - */ + * Function for testing binomialCoeffSum function. + * test cases and assert statement. + * @returns `void` +*/ static void test() { - int test_case_1=binomialCoeffSum(4); - assert(test_case_1==16); - cout<<"Test_case_1 Passed!"<>number; - assert(number>=0); - cout<<"Sum of binomial coefficient is "<