Thursday, 16 November 2017

C program to Calculate the value of nCr


Code:

#include   stdio.h

int fact(int z);

void main()
{
    int n, r, ncr;

    printf("\n Enter the value for N and R \n");
    scanf("%d%d", &n, &r);
    ncr = fact(n) / (fact(r) * fact(n - r));
    printf("\n The value of ncr is: %d", ncr);
}

int fact(int z)
{
    int f = 1, i;
    if (z == 0)
    {
        return(f);
    }
    else
    {
        for (i = 1; i <= z; i++)
{
            f = f * i;
}
    }
    return(f);
}


Output:

Enter the value for N and R
5 2

The value of ncr is: 10


More C Programs:











100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...