User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 427,092 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,260 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums

Custom pascal triangle ?

Join Date: Sep 2004
Posts: 6,332
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 28
Solved Threads: 458
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Custom pascal triangle ?

  #5  
Jul 11th, 2006
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();
}
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
All times are GMT -4. The time now is 5:17 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC