

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to calculate the value of nPr in C Program
Given with the n P r, where P represents Permutation, n represents total numbers and r represents arrangement the task is to calculate the value of nPr.
Permutation is the arrangement of data in a sequence or order. Permutation and combination differs in the sense that permutation is the process of arranging whereas combination is the process of selection of elements from the given set.
Formula for permutation is −
nPr = (n!)/(n-r)!
Example
Input-: n=5 r=2 Output-: 20
Algorithm
Start Step 1 -> declare function to calculate value of nPr int cal_n(int n) IF n <=1 Return 1 End return n*cal_n(n-1) Step 2 -> Declare function to calculate the final npr int nPr(int n, int r) return cal_n(n)/cal_n(n-r) Step 3 -> In main() Declare variables as int n=5, r=2 Print nPr(n, r) Stop
Example
#include<stdio.h> //function to calculate the factorial for npr int cal_n(int n){ if (n <= 1) return 1; return n*cal_n(n-1); } //function to calculate the final npr int nPr(int n, int r){ return cal_n(n)/cal_n(n-r); } int main(){ int n=5, r=2; printf("value of %dP%d is %d", n, r, nPr(n, r)); return 0; }
Output
value of 5P2 is 20
- Related Questions & Answers
- C program to calculate the value of nPr?
- Program to calculate value of nCr in C++
- C Program find nCr and nPr.
- C++ Program to calculate the value of sin(x) and cos(x)
- Program to Calculate the Perimeter of a Decagon in C program
- C program to calculate age
- C program to calculate the standard deviation
- Program to calculate volume of Ellipsoid in C++
- C++ program to Calculate the Edge Cover of a Graph
- C++ Program to Calculate Sum of Natural Numbers
- C++ Program to Calculate Power of a Number
- C++ Program to calculate Bitonicity of an Array
- C++ Program to calculate the profit sharing ratio
- C++ Program to Calculate Standard Deviation
- C++ Program to calculate Double Integration
Advertisements