<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: combinations code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Wed, 08 Oct 2008 04:42:46 GMT</pubDate>
    <description>DZone Snippets: combinations code</description>
    <item>
      <title>Factorial function</title>
      <link>http://snippets.dzone.com/posts/show/4257</link>
      <description>A (non-recursive) factorial function&lt;br /&gt;&lt;code&gt;int factorial(int x) {&lt;br /&gt; int fac = 1;&lt;br /&gt; for (int i=2; i&lt;=x; i++) fac *= i;&lt;br /&gt; return fac;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Also, with this function defined, you can use two macros for calculating combinations &amp; permutations:&lt;br /&gt;&lt;code&gt;#define nCr(n, r) (factorial(n) / factorial(n-r) / factorial(r))&lt;br /&gt;#define nPr(n, r) (factorial(n) / factorial(n-r))&lt;/code&gt;</description>
      <pubDate>Thu, 05 Jul 2007 03:50:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4257</guid>
      <author>Minimiscience (Guildorn Tanaleth)</author>
    </item>
  </channel>
</rss>
