{"id":24972,"date":"2017-10-15T13:55:30","date_gmt":"2017-10-15T08:25:30","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=24972"},"modified":"2017-10-15T13:55:30","modified_gmt":"2017-10-15T08:25:30","slug":"c-program-find-ncr-npr","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/c-program-find-ncr-npr\/","title":{"rendered":"C program to find ncr and npr"},"content":{"rendered":"<p>C program to find nCr and nPr: This code calculate nCr which is n!\/(r!*(n-r)!) and nPr = n!\/(n-r)!<\/p>\n<h2 id=\"c-program-to-find-ncr-using-function\">C program to find nCr using function<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">find nCr using function<\/span> <\/div> <pre class=\"language-c code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-c code-embed-code\">#include &lt;stdio.h&gt;<br\/> <br\/>long factorial(int);<br\/>long find_ncr(int, int);<br\/>long find_npr(int, int);<br\/> <br\/>int main()<br\/>{<br\/>   int n, r;<br\/>   long ncr, npr;<br\/> <br\/>   printf(&quot;Enter the value of n and r\\n&quot;);<br\/>   scanf(&quot;%d%d&quot;,&amp;n,&amp;r);<br\/> <br\/>   ncr = find_ncr(n, r);<br\/>   npr = find_npr(n, r);<br\/> <br\/>   printf(&quot;%dC%d = %ld\\n&quot;, n, r, ncr);<br\/>   printf(&quot;%dP%d = %ld\\n&quot;, n, r, npr);<br\/> <br\/>   return 0;<br\/>}<br\/> <br\/>long find_ncr(int n, int r) {<br\/>   long result;<br\/> <br\/>   result = factorial(n)\/(factorial(r)*factorial(n-r));<br\/> <br\/>   return result;<br\/>}<br\/> <br\/>long find_npr(int n, int r) {<br\/>   long result;<br\/> <br\/>   result = factorial(n)\/factorial(n-r);<br\/> <br\/>   return result;<br\/>} <br\/> <br\/>long factorial(int n) {<br\/>   int c;<br\/>   long result = 1;<br\/> <br\/>   for (c = 1; c &lt;= n; c++)<br\/>      result = result*c;<br\/> <br\/>   return result;<br\/>}<\/code><\/pre> <\/div>\n<p>Output of program:<\/p>\n<h2 id=\"another-way-to-calculate-npr-and-ncr-using-functions\">Another way to calculate nPr and nCr using functions<\/h2>\n<p>We use long long data type in our program to handle large numbers.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-c code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-c code-embed-code\">#include &lt;stdio.h&gt;<br\/>#define ll long long<br\/> <br\/>void find_ncr_npr(int, int, ll*, ll*);<br\/>ll find_npr(int, int);<br\/>ll factorial(int);<br\/> <br\/>int main() {<br\/>   int n, r;<br\/>   ll ncr, npr;<br\/> <br\/>   printf(&quot;Input n and r\\n&quot;);<br\/>   scanf(&quot;%d%d&quot;, &amp;n, &amp;r);<br\/> <br\/>   find_ncr_npr(n, r, &amp;npr, &amp;ncr);<br\/> <br\/>   printf(&quot;%dC%d = %lld\\n&quot;, n, r, ncr);<br\/>   printf(&quot;%dP%d = %lld\\n&quot;, n, r, npr);<br\/> <br\/>   return 0;<br\/>}<br\/> <br\/>void find_ncr_npr(int n, int r, ll *npr, ll *ncr) {<br\/>   *npr = find_npr(n, r);<br\/>   *ncr = *npr\/factorial(r);<br\/>}<br\/> <br\/>ll find_npr(int n, int r) {<br\/>   ll result = 1;<br\/>   int c = 1;<br\/> <br\/>   while (c &lt;= r) {<br\/>      result = result * (n - r + c);<br\/>      c++;<br\/>   }<br\/> <br\/>   return result;<br\/>}<br\/> <br\/>ll factorial(int n) {<br\/>   int c;<br\/>   ll result = 1;<br\/> <br\/>   for (c = 1; c &lt;= n; c++)<br\/>      result = result*c;<br\/> <br\/>   return result;<br\/>}<\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n","protected":false},"excerpt":{"rendered":"<p>C program to find ncr and npr &#8211; C Programming &#8211; C program to find nCr and nPr: This code calculate nCr which is n!\/(r!*(n-r)!) and nPr = n!\/(n-r)!<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69866,1],"tags":[70335,70324,70363,70352,70364,70333,70332,70365,70381,70339,70346,70334,70361,70349,70378,70372,70359,70383,70362,70375,70373,70360,70368,70354,70341,70356,70330,70342,70327,70345,70371,70350,70325,70382,70367,70323,70348,70377,70351,70331,70369,70374,70326,70340,70370,70344,70338,70366,70328,70379,70384,70329,70355,70347,70353,70343,70336,70337,70358,70357,70376,70380],"class_list":["post-24972","post","type-post","status-publish","format-standard","hentry","category-c-programming","category-coding","tag-bca-course-syllabus","tag-bca-syllabus","tag-c-program-to-find-factorial","tag-calculate-combinations","tag-combination-and-permutation-formula","tag-combination-calculator","tag-combination-formula","tag-combination-formula-calculator","tag-combination-formula-ncr","tag-combinations-and-permutations","tag-difference-between-combination-and-permutation","tag-difference-between-permutation-and-combination","tag-difference-between-permutations-and-combinations","tag-formula-for-combinations","tag-formula-for-ncr","tag-formula-for-permutation-and-combination","tag-formula-for-permutations","tag-formula-of-ncr","tag-formula-of-permutation","tag-formula-of-permutation-and-combination","tag-how-to-solve-combinations","tag-how-to-switch-off-calculator","tag-how-to-turn-off-calculator","tag-meaning-of-ncr","tag-ncr-calculator","tag-ncr-combination","tag-ncr-formula","tag-ncr-math","tag-ncr-means","tag-npr-formula","tag-npr-full-form","tag-npr-meaning","tag-npr-number","tag-npr-number-means","tag-npr-permutation","tag-permutation-and-combination","tag-permutation-and-combination-calculator","tag-permutation-and-combination-difference","tag-permutation-and-combination-examples","tag-permutation-and-combination-formula","tag-permutation-and-combination-formula-pdf","tag-permutation-and-combination-meaning","tag-permutation-and-combination-pdf","tag-permutation-and-combination-problems","tag-permutation-and-combination-problems-and-solutions","tag-permutation-calculator","tag-permutation-combination","tag-permutation-combination-formula","tag-permutation-formula","tag-permutation-in-c","tag-permutation-program-in-c","tag-permutations-and-combinations","tag-permutations-and-combinations-examples","tag-permutations-and-combinations-formula","tag-permutations-and-combinations-problems","tag-permutations-calculator","tag-syllabus-of-bca","tag-what-is-ncr","tag-what-is-npr-number","tag-what-is-permutation-and-combination","tag-what-is-the-meaning-of-ncr","tag-when-to-use-permutation-and-combination"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/24972","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=24972"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/24972\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=24972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=24972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=24972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}