CODE OF GEEKS


A PLATFORM TO LEARN | CODE | ACHIEVE


" Programming is the real test of your creativity,its all about how you turn ideas into codes. "



Connect :


THIS WEBSITE IS BEST VIEWED IN THE GOOGLE CHROME WEB BROWSER.



TO GENERATE nCr AND nPr IN C

Code

#include<stdio.h>
int fact(int num)
{
int f=1;
int i;
for(i=1;i<=num;i++)
{
  f=f*i;	
}
return f;
}
int main()
{
int n,r;
int ncr,npr;
printf("nCr & nPr CALCULATOR :\n");
printf("ENTER THE VALUES OF n & r :\n");
scanf("%d %d",&n;,&r;);
ncr=fact(n)/(fact(r)*fact(n-r));
npr=fact(n)/(fact(n-r));
printf("%dC%d : %d\n",n,r,ncr);
printf("%dP%d : %d",n,r,npr);
return 0;
}

Output


nCr & nPr CALCULATOR :
ENTER THE VALUES OF n & r :10 8
10C8 : 45
10P8 : 1814400


What we did - Our Approach


In this problem we have to generate the measure of nCr and nPr for given values of 'n' and 'r'. We have following formulaes to calculate nCr and nPr respectively :

nCr = n! / r!*(n-r)!

nPr = n! /(n-r)!

Now after breaking this formula,we see that,all we have to do is find the factorial of each parameter i.e n,r,n-r. So,after finding the factorial,we put the values in formula.

See this code in :


C++

Java

Participate in our MONTHLY CHALLENGE,and get a chance to get listed on our site and win the TITLE of "MR.GEEK".


RUSH TO OUR MONTHLY CHALLENGE

Join us :



CODE OF GEEKS

A Platform to LEARN | CODE | ACHIEVE

Connect :



INTERESTING READ FOR YOU :

TOP PROGRAMMING LANGUAGES THAT ARE RULING IN 2018.
TOP PROGRAMMING LANGUAGES FOR WEB DEVELOPMENT IN 2018.

SHARE:



For any Queries,suggestions,feel free to Mail us at :
[email protected]

For reporting any kind of copyright voilation,mail us at : [email protected]

© copyright CODE OF GEEKS 2018