Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Sum of squares of binomial coefficients in C++
The binomial coefficient is a quotation found in a binary theorem which can be arranged in a form of pascal triangle it is a combination of numbers which is equal to nCr where r is selected from a set of n items which shows the following formula
nCr=n! / r!(n-r)! or nCr=n(n-1)(n-2).....(n-r+1) / r!
The sum of the square of Binomial Coefficient i.e (nC0)2 + (nC1)2 + (nC2)2 + (nC3)2 + ……… + (nCn-2)2 + (nCn-1)2 + (nCn)2
Input :n=5 Output:252
Explanation
In this program first we have to find the binomial coefficient of r which is selected from n set then we have to square each coefficient and sum them we can derive a formula from the above equation or use of factorial function of each digit to get a sum so we will fall or factorial function in which we will pass and r for a given equation and then add it then we get the solution
Example
#include <iostream>
using namespace std;
int fact(int n){
int fact = 1, i;
for (i = 2; i <= n; i++){
fact *= i;
}
return fact;
}
int main(){
int n=5;
int sum = 0;
int temp=0;
for (int r = 0; r <= n; r++){
temp = fact(n)/(fact(r)*fact(n-r));
sum +=(temp*temp);
}
cout<<sum;
return 0;
}
Output
252
Advertisements