Jinson Jacob -3 Newbie Poster
#include<iostream>
using namespace std;
int fact(int);
main()
{
    int rows,i,j,k;
    cout<<"Enter the numbe of rows you want in the triangle:";
    cin>>rows;
    for(i=0;i<rows;i++)
    {
        //Moving each row by rows-i spaces to get a triangular shape
        for(k=0;k<(rows-i);k++)
        cout<<" ";
        //Loop for printing each row
        for(j=0;j<=i;j++)
        cout<<" "<<fact(i)/(fact(j)*fact(i-j)); //nCr=n!/(r!*(n-r)!)
        cout<<endl;
    }
}

int fact(int i)
{
    int value=1;
    while(i!=0)
    {
        value=value*i;
        i--;
    }
    return value;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.