12
Permut
- int fact( int n ) {
- if ( n < 0 )
- return 0;
- int f = 1;
- while ( n > 1 )
- f *= n--;
- return f;
- }
- extern int fact( int );
- int permut( int n, int k ) {
- if ( n < 0 || k < 0 || k > n )
- return 0;
- return fact( n ) / fact( n - k );
- }
- #include <iostream>
- using std::cout;
- using std::endl;
- int main() {
- extern int permut( int, int );
- for ( int i = 0; i < 10; i++ ) {
- cout << i;
- for ( int j = 0; j <= i; j++ )
- cout << " " << permut( i, j );
- cout << endl;
- }
- }
Comments