C Program to Find nPr

C Program to Find nPr

C program to find npr; Through this tutorial, we will learn how to find npr in c program.

In mathematics, nPr is the permutation of arrangement of ‘r’ objects from a set of ‘n’ objects, into an order or sequence. The formula to find permutation is: nPr = (n!) / (n-r)! Combination, nCr, is the selection of r objects from a set of n objects, such that order of objects does not matter.

C Program to Find nPr

// C Program To Calculate The Value on nPr
#include <stdio.h>
int fact(int n){
    int i, a = 1;
    for (i = 1; i <= n; i++){
        a = a * i;
    return a;
int main(){
    int n, r, npr;
    // Asking for Input
    printf("Enter the value of n: ");
    scanf("%d", &n);
    printf("Enter the value of p: ");
    scanf("%d", &r);
    npr = fact(n) / fact(n-r);
    printf("The Value of P(%d,%d) is %d.", n, r, npr);
    return 0;

The output of the above c program; as follows:

Enter the value of n: 5
Enter the value of p: 3
The Value of P(5,3) is 60.

Recommended C Programs


Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *