12

Permut

  1. int fact( int n ) {
  2.     if ( n < 0 )
  3.         return 0;
  4.  
  5.     int f = 1;
  6.  
  7.     while ( n > 1 )
  8.         f *= n--;
  9.  
  10.     return f;
  11. }
  1. extern int fact( int );
  2.  
  3. int permut( int n, int k ) {
  4.     if ( n < 0 || k < 0 || k > n )
  5.         return 0;
  6.  
  7.     return fact( n ) / fact( n - k );
  8. }
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::endl;
  5.  
  6. int main() {
  7.     extern int permut( int, int );
  8.  
  9.     for ( int i = 0; i < 10; i++ ) {
  10.         cout << i;
  11.         for ( int j = 0; j <= i; j++ )
  12.             cout << " " << permut( i, j );
  13.         cout << endl;
  14.     }
  15. }

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].