C Program to Find ncr

C Program to Find ncr

C program to find ncr; Through this tutorial, we will learn how to find ncr in c program.

In mathematics, combination or nCr, is the method of selection of ‘r’ objects from a set of ‘n’ objects where the order of selection does not matter.

nCr = n!/[r!(n-r)!]

C Program to Find ncr

// C program to calculate the value of nCr

#include <stdio.h>

int getFactorial(int num)
{
    int f = 1;
    int i = 0;

    if (num == 0)
        return 1;

    for (i = 1; i <= num; i++)
        f = f * i;

    return f;
}

int main()
{
    int n = 0;
    int r = 0;

    int nCr = 0;

    printf("Enter the value of N: ");
    scanf("%d", &n);

    printf("Enter the value of R: ");
    scanf("%d", &r);

    nCr = getFactorial(n) / (getFactorial(r) * getFactorial(n - r));

    printf("The nCr is: %d\n", nCr);

    return 0;
}

The output of the above c program; as follows:

Enter the value of N: 7
Enter the value of R: 3
The nCr is: 35

Recommended C Programs

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *