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


My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of 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 from a starting stage. As well as demo example.

Leave a Reply

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