#include <iostream.h>
#include<iomanip.h>
long comb (int , int ); // Function Declaration
void main( )
{
const int m = 9;
int j;
for (int i = 0; i < m; i++)
{
for (j = 1 ; j < m - i; j++)
cout<<setw(2)<<" "; //print whitespace
for (j = 0 ; j <= i; j++)
cout << setw(4) << comb( i, j);
cout<<endl;
}
}
long comb(int n, int k)
{
if (n < 0 || k < 0 || k > n) return 0;
long c = 1;
for ( int i =1; i <= k; i++, n--)
c = c * n/i ;
return c;
}
0 comments:
Post a Comment