Binomial Coefficients in C++

0
1297
Area and Perimeter of rectangle in C++
Finding Greatest Common Divisor of 2 numbers in C++

How we implement a logic to find out the binomial coefficients of an entered number by the user in C++?. Look at the below code:


    # include <iostream>
    using namespace std;
     
    int my_func(int x)    //defination
    {
     
        if (x==0)
        return 1;
     
        else 
     
            return x*my_func(x–1);
    }
     
    int bionomial_func(int power,int y)    //defination
    {
     
        cout<<” “;
        return my_func(power)/(my_func(y)*my_func(power–y));
         
    }
     
    void main()
    {
        int a;
        
        cout<<“enter binomial expression= “;    //enter the expression
     
        cin>>a;    
        
        cout<<“coefficients are”;
        cout<<endl;
     
        for(int i = 0; i <=a; ++i)
     
        {
            cout<<bionomial_func(a,i);
        } 
     
        cout<<endl;
    }

In the code for Binomial Coefficients we defined a function binomial_func()  in which we implemented the login of finding the binomial coefficients.

Area and Perimeter of rectangle in C++
Finding Greatest Common Divisor of 2 numbers in C++

Leave a Reply