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