C Program to Calculate the nPr

Write a C program to calculate or find the nPr. The mathematical formula to calculate nPr is nPr = n!/((n – r)!). This C example allows entering the n and r value 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;
    return Number * numFactorial (Number -1);

int main()
    int n, r, nprResult;
    printf("Enter the Number to calculate nPr  = ");

    printf("Enter the r value to calculate nPr = ");

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

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