Our website is made possible by displaying online advertisements to our visitors.Please consider supporting us by disabling your ad blocker.
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Translate it in your own Language

Print this Job Post

Print Friendly and PDF

Saturday, May 3, 2014

C program to find ncr and npr

C program to find nCr and nPr: This code calculate nCr which is n!/(r!*(n-r)!) and nPr = n!/(n-r)!

C program to find nCr using function

long factorial(int);
long find_ncr(int, int);
long find_npr(int, int);
void main()
   int n, r;
   long ncr, npr;
   printf("Enter the value of n and r\n");
   ncr = find_ncr(n, r);
   npr = find_npr(n, r);
   printf("%dC%d = %ld\n", n, r, ncr);
   printf("%dP%d = %ld\n", n, r, npr);
long find_ncr(int n, int r)
   long result;
   result = factorial(n)/(factorial(r)*factorial(n-r));
   return result;
long find_npr(int n, int r)
   long result;
   result = factorial(n)/factorial(n-r);
   return result;
long factorial(int n)
   int c;
   long result = 1;
   for( c = 1 ; c <= n ; c++ )
      result = result*c;
   return ( result );

No comments:

Post a Comment

Copyright @ CrackMNC 2014-2024
Divas Nikhra Theme by Crack MNC