C Program to Calculate the nCr

Write a C program to find or calculate the nCr. This combination formula can also represent as C(n, r). The mathematical formula to calculate nCr is nCr = n!/( r!(n – r)!). This program allows entering the n and r value and calculates the nCr. Here, we created a function that returns the factorial of a given number.

#include <stdio.h>

int factorial(int Number)
  if (Number == 0 || Number == 1)
    return 1;
    return Number * factorial (Number -1);

int main()
    int n, r, ncrResult;
    printf("Enter the Number  = ");

    printf("Enter the r Value = ");

    ncrResult = factorial(n)/ (factorial(r) * factorial(n - r));

    printf("The Final Result of nCr = %d\n", ncrResult);
    return 0;
C Program to Calculate the nCr 1

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.