Find the permutation of a given number using C (Beginner level)
Hey guys once again welcome to the Decoders blog, I hope you all are doing well and today I'm present with another logic but this time with something different it is a C logic which will help us to calculate the permutation value of any given combination (using C).
#include<stdio.h>
int fac(int num)
{
int i=1,fac=1;
while(i<=num)
{
fac=fac*i;
i++;
}
return(fac);
}
int main()
{
int num,r;
printf("Enter the value of n and r:");
scanf("%d%d",&num,&r);
int numerator=fac(num);
int denominator=fac((num-r));
int answer=numerator/denominator;
printf("The value of the factorial is %d",answer);
return (0);
}
Comments
Post a Comment