Created
January 22, 2019 21:44
Star
You must be signed in to star a gist
Binomial theorem in c++ with another method
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 N\n"; | |
cin>>n; | |
sum=pow(x,n); | |
for(r=0; r<=n; r++) { | |
//Method 1 | |
if(r==0){ | |
cout<<"X^"<<n<<"+"; | |
continue; | |
} | |
if(r==n){ | |
cout<<"Y^"<<n; | |
continue; | |
} | |
cout<<n<<"C"<<r<<"X^(n-"<<r<<")Y^"<<r<<"+"; | |
// Method 2 | |
// cout<<n<<"C"<<r<<"X^(n-"<<r<<")Y^"<<r; | |
// if(r<n) | |
// cout<<"+"; | |
} | |
cout<<"\nGive the value of X\n"; | |
cin>>x; | |
cout<<"Give the value of Y\n"; | |
cin>>y; | |
sum=pow(x+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