Calculate nPr C Program

By | September 1, 2016

C Program To Calculate nPr Value

Learn How To Calculate nPr in C Programming Language. This C Program makes use of the Factorial Function in C Programming to find the Value of nPr. nPr is also commonly written as P(n/r).

This C Code to Find Value of nPr finds the total Number of different Permutations of n Distinct Points taken r at a time. An important part of finding combination in C Programming is calculation of the Factorial of a Number.

Mathematical Formula To Find Permutation P(n, r)

Find Value of nPr in C Programming using Functions

C Program To Calculate nPr using Function

#include<stdio.h>

int Factorial(int x)
{
      int factorial = 1, count;
      for(count = x; count > 1; count--)
      {
            factorial =  factorial * count;
      }
      return  factorial;
}

int main()
{	
      int n, r;
      float result;
      printf("Enter value of N:\t");
      scanf("%d", &n);
      printf("Enter value of R:\t");
      scanf("%d", &r);
      result = (float)Factorial(n) / Factorial(n - r);
      printf("\nValue of nPr:\t %.2f\n", result);
      return 0;
}

Method 2: C Program To Find Value of nPr using While Loop

#include<stdio.h>

int Factorial(int x)
{
      int factorial = 1, count = x;
      while(count > 1)
      {
            factorial = factorial * count;
            count--;		
      }
      return factorial;
}

int main()
{	
      int n, r;
      float result;
      printf("Enter value of N:\t");
      scanf("%d", &n);
      printf("Enter value of R:\t");
      scanf("%d", &r);
      result = (float)Factorial(n) / Factorial(n - r);
      printf("\nValue of nPr:\t %.2f\n", result);
      return 0;
}

Output

C Program To Calculate nPr with Function

If you have any compilation error or doubts in this C Program To Compute nPr with and without Functions, let us know about it in the Comment Section below.

Recommended Programs
C Program To Calculate Value of nCr
Calculation of Simple Interest using Functions in C Programming
Trapezoidal Rule C Program using Functions
C Program For Binary into Decimal Conversion
C Program To Implement Simpsons Rule
C Program To Raise an Positive Number to a Power
C Program To Solve Compound Interest

4 thoughts on “Calculate nPr C Program

  1. Ritik Sharma

    This is just awesome! Thank you so much! I could finally complete my C Programming assignment! 🙂

    Reply
  2. Pushkar Gaikwad

    I think that I can now convert most of my mathematical problems into C program codes now. 🙂

    Reply
  3. Sunil Kakade

    A Permutation is an arrangement of a number of objects in a definite order.

    Reply

Let's Discuss