Pascal's triangle is boring. How about something more fractalish:
#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
int rows = 16;
for ( int i = 0; i < rows; i++ ) {
cout<< setw ( rows - i - 1 ) <<"";
for ( int j = 0; j <= i; j++ )
cout<< ( ( ~i & j ) ? ' ' : '*' ) <<' ';
cout<<'\n';
}
cin.get();
}
>Here i am trying to design a custom pascal triangle where the user can
>specify the TOP ELEMENT as well as both the CORNER elements.
That's not very logical. Can you give a few examples?
>Err...
>Please elaborate if possible.
Take note of the ncr function:
#include <iostream>
using namespace std;
double factorial ( double n )
{
return ( n > 1 ) ? n * factorial ( n - 1 ) : 1;
}
double ncr ( int n, int r )
{
return factorial ( n ) / ( factorial ( r ) * factorial ( n - r ) );
}
int main()
{
cout.setf ( ios::fixed, ios::floatfield );
cout.precision ( 0 );
for ( int i = 0; i < 15; i++ ) {
for ( int j = 0; j <= i; j++ )
cout<< right << ncr ( i, j ) <<' ';
cout<<'\n';
}
cin.get();
}