#include <iostream>
using namespace std;
int fact(int x){           //here this function finds the factorial of the number feeded by the ncr function
    int f=1;
    for(int i=1; i<=x; i++){
        f=f*i;
    }
    return f;
}

int ncr(int n , int r){    // the values of n and r are feeded by main function 
    int a = fact(n);        //here the fact function is finding the factorial of n and r by feeding the n and r values to the fact function
    int b = fact(r);
    int c = fact(n-r);
    return a/(b*c);
}

int main() {           // this function is feeding values in ncr function 
    int n; 
    cin>>n;
    int a;
    a=1;
    for(int i = 0; i<=n; i++){
        for(int j =0; j<=i; j++){
            cout<<ncr(i,j)<<" ";     //here the values are feeded to the ncr function
        }
       
        cout<<endl;
    }
    
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: