Find the combination 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 combination value of  any given number (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 mul=fac(r);
    int den=fac((num-r));
    int denominator=mul*den;
    int answer=numerator/denominator;
    printf("The value of the factorial is %d",answer);
    return (0);
}

Comments

Popular Posts