{"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[pastacode lang=\u201dc\u201d manual=\u201d%23include%20%3Cstdio.h%3E%0A%20%0Along%20factorial(int)%3B%0Along%20find_ncr(int%2C%20int)%3B%0Along%20find_npr(int%2C%20int)%3B%0A%20%0Aint%20main()%0A%7B%0A%20%20%20int%20n%2C%20r%3B%0A%20%20%20long%20ncr%2C%20npr%3B%0A%20%0A%20%20%20printf(%22Enter%20the%20value%20of%20n%20and%20r%5Cn%22)%3B%0A%20%20%20scanf(%22%25d%25d%22%2C%26n%2C%26r)%3B%0A%20%0A%20%20%20ncr%20%3D%20find_ncr(n%2C%20r)%3B%0A%20%20%20npr%20%3D%20find_npr(n%2C%20r)%3B%0A%20%0A%20%20%20printf(%22%25dC%25d%20%3D%20%25ld%5Cn%22%2C%20n%2C%20r%2C%20ncr)%3B%0A%20%20%20printf(%22%25dP%25d%20%3D%20%25ld%5Cn%22%2C%20n%2C%20r%2C%20npr)%3B%0A%20%0A%20%20%20return%200%3B%0A%7D%0A%20%0Along%20find_ncr(int%20n%2C%20int%20r)%20%7B%0A%20%20%20long%20result%3B%0A%20%0A%20%20%20result%20%3D%20factorial(n)%2F(factorial(r)*factorial(n-r))%3B%0A%20%0A%20%20%20return%20result%3B%0A%7D%0A%20%0Along%20find_npr(int%20n%2C%20int%20r)%20%7B%0A%20%20%20long%20result%3B%0A%20%0A%20%20%20result%20%3D%20factorial(n)%2Ffactorial(n-r)%3B%0A%20%0A%20%20%20return%20result%3B%0A%7D%20%0A%20%0Along%20factorial(int%20n)%20%7B%0A%20%20%20int%20c%3B%0A%20%20%20long%20result%20%3D%201%3B%0A%20%0A%20%20%20for%20(c%20%3D%201%3B%20c%20%3C%3D%20n%3B%20c%2B%2B)%0A%20%20%20%20%20%20result%20%3D%20result*c%3B%0A%20%0A%20%20%20return%20result%3B%0A%7D\u201d message=\u201dfind nCr using function\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\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[pastacode lang=\u201dc\u201d manual=\u201d%23include%20%3Cstdio.h%3E%0A%23define%20ll%20long%20long%0A%20%0Avoid%20find_ncr_npr(int%2C%20int%2C%20ll*%2C%20ll*)%3B%0All%20find_npr(int%2C%20int)%3B%0All%20factorial(int)%3B%0A%20%0Aint%20main()%20%7B%0A%20%20%20int%20n%2C%20r%3B%0A%20%20%20ll%20ncr%2C%20npr%3B%0A%20%0A%20%20%20printf(%22Input%20n%20and%20r%5Cn%22)%3B%0A%20%20%20scanf(%22%25d%25d%22%2C%20%26n%2C%20%26r)%3B%0A%20%0A%20%20%20find_ncr_npr(n%2C%20r%2C%20%26npr%2C%20%26ncr)%3B%0A%20%0A%20%20%20printf(%22%25dC%25d%20%3D%20%25lld%5Cn%22%2C%20n%2C%20r%2C%20ncr)%3B%0A%20%20%20printf(%22%25dP%25d%20%3D%20%25lld%5Cn%22%2C%20n%2C%20r%2C%20npr)%3B%0A%20%0A%20%20%20return%200%3B%0A%7D%0A%20%0Avoid%20find_ncr_npr(int%20n%2C%20int%20r%2C%20ll%20*npr%2C%20ll%20*ncr)%20%7B%0A%20%20%20*npr%20%3D%20find_npr(n%2C%20r)%3B%0A%20%20%20*ncr%20%3D%20*npr%2Ffactorial(r)%3B%0A%7D%0A%20%0All%20find_npr(int%20n%2C%20int%20r)%20%7B%0A%20%20%20ll%20result%20%3D%201%3B%0A%20%20%20int%20c%20%3D%201%3B%0A%20%0A%20%20%20while%20(c%20%3C%3D%20r)%20%7B%0A%20%20%20%20%20%20result%20%3D%20result%20*%20(n%20-%20r%20%2B%20c)%3B%0A%20%20%20%20%20%20c%2B%2B%3B%0A%20%20%20%7D%0A%20%0A%20%20%20return%20result%3B%0A%7D%0A%20%0All%20factorial(int%20n)%20%7B%0A%20%20%20int%20c%3B%0A%20%20%20ll%20result%20%3D%201%3B%0A%20%0A%20%20%20for%20(c%20%3D%201%3B%20c%20%3C%3D%20n%3B%20c%2B%2B)%0A%20%20%20%20%20%20result%20%3D%20result*c%3B%0A%20%0A%20%20%20return%20result%3B%0A%7D\u201d message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\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}]}}