Created
January 14, 2019 14:51
-
-
Save prodhan/49d1db7d5ffaf26231167f65c819e6a0 to your computer and use it in GitHub Desktop.
Binomial theorem in c++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Created By Ariful Islam | |
Batch E-64 (DIU) | |
Roll: 34 | |
*/ | |
#include<iostream> | |
#include <math.h> | |
using namespace std; | |
int factorial(int a) | |
{ | |
if(a<=1) | |
{ | |
return 1; | |
} | |
else | |
{ | |
return a*factorial(a-1); | |
} | |
} | |
int nCr(int p, int q) | |
{ | |
return factorial(p)/(factorial(p-q)*factorial(q)); | |
} | |
int main() | |
{ | |
int x,y,n,r; | |
double sum=0, temp=0; | |
cout<<"Give the value of X\n"; | |
cin>>x; | |
cout<<"Give the value of Y\n"; | |
cin>>y; | |
cout<<"Give the value of N\n"; | |
cin>>n; | |
sum=pow(x,n); | |
r=1; | |
for(r=1; r<=n; r++) { | |
temp=(nCr(n, r))*(pow(x, (n-r)))*(pow(y, r)); | |
sum=sum+temp; | |
} | |
// sum=sum+pow(y,n); | |
cout<<"Result : "<<sum; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment