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

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of 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 from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published.