C Program to Calculate the nPr

Write a C program to calculate or find the nPr and the mathematical formula to calculate is = n!/((n – r)!). This example allows entering the n and r values and calculates the nPr. Here, we created a numFactorial function that returns the factorial of a given number.

#include <stdio.h>

int numFactorial(int Number)
{ 
  if (Number == 0 || Number == 1)  
    return 1;
  else
    return Number * numFactorial (Number -1);
}

int main()
{
    int n, r, Result;
    
    printf("Enter the Number to calculate  = ");
    scanf("%d",&n);

    printf("Enter the r value to calculate = ");
    scanf("%d",&r);

    Result = numFactorial(n)/ numFactorial(n - r);

    printf("The Final Result = %d\n", Result);
    
    return 0;
}
C Program to Calculate the nPr 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.