C program to Calculate the value of nCr

C program to Calculate the value of nCr

    #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);

    }

Share this post


Comments (0)

  • Be first to comment

Leave a comment

or to Comment

Contact Us

  • Address: # 650 Narsi Village Sector 32 Urban Estate Karnal-132001 Haryana, India

  • Phone:(+91) 97289-77666   Email: codethor84@gmail.com


Follow Us