- Hello World c
- C Program to Add Two Numbers
- Area of Triangle C
- Odd or Even C
- Write a C program to find the sum of digitis of a given number
- Write a C program to find the maximum of three numbers
- Write a C program to swap two number using third variable
- Write a C program to swap to numbers without using third variable
- Write a C program to calculate the area of circle
- Write a C program to calculate the Binomial Coefficient (nCr)
- Write a C program to calculate the permutations (nPr)
- Write a C program to reverse the number
- Write a c program to check the given number is palindrome or not
- Write a c program to check the given number prime or not
- Write a c program to check the given number is armstrong or not
- Write a C program to generate all Armstrong number till n
- Write a program to check given number perfect or not
- Write a C program to check alphabet is vowel or consonant
- Write C program to calculates the factorial of a given number
- Write a C program generate and prints the Fibonacci series up to a user-defined limit
- Write a C program to calculate the nth number in the Fibonacci series using recursion
- Write a C program to find the maximum element in the array
- Write a C program to find the minimum element in the array
- Write a C program to search the element using linear search technique
- Write a C program to Insert element in array

In mathematics, **nPr (n Permute r)** represents the number of ways to select and arrange *r* objects from a set of *n* distinct objects, where order matters and repetition is not allowed. The formula for *nPr* is given by: **nPr = n! / (n-r)!**, Where n! represents the factorial of n (i.e., the product of all positive integers up to n) and (n-r)! represents the factorial of the difference between n and r.

```
// Write a c program to calculate the Permutation nPr.
#include<stdio.h>
int factorial(int n){
int fact = 1;
for(int i = 1; i <= n; i++){
fact *= i;
}
return fact;
}
int nPr(int n, int r){
int nPr = factorial(n) / factorial(n - r);
return nPr;
}
int main(){
int n, r;
printf("Enter the value of n : ");
scanf("%d", &n);
printf("Enter the value of r : ");
scanf("%d", &r);
int result = nPr(n, r);
printf("nPr = %d", result);
return 0;
}
```

`#include<stdio.h>`

This line of code includes the **standard input/output library**, which provides the function for input and output operations.

```
// factorial function to calculate the factorial.
int factorial(int n){
int fact = 1;
for(int i = 1; i <= n; i++){
fact *= i;
}
return fact;
}
```

This is a function called factorial that takes an integer n and returns the **factorial** of n. The for loop iterates from **i = 1** to **i = n** and multiplies **fact** by *i* in each iteration. Finally, the *fact* is returned.

```
int nPr(int n, int r){
int nPr = factorial(n) /factorial(n - r);
return nCr;
}
```

This is another function called nPr that takes two integers n and r, and returns the number of **permutations** of *n* things takes *r* at a time. It calculates the permutations using the formula * nPr = n! / (n - r)!,* where

```
// main function (entry point of every program).
int main(){
int n, r;
printf("Enter the value of n : ");
scanf("%d", &n);
printf("Enter the value of r : ");
scanf("%d", &r);
int result = nPr(n, r);
printf("nPr = %d", result);
return 0;
}
```

This is the **main function** where the program execution starts. It declares two integer variables * n* and

- Include the standard
**input/output**library. - Define a function to calculate the
**factorial**of a given integer n. - Define a function to calculate the
**permutations nCr**using the factorial function. - In the main function, read input values for n and r using the
**scanf() function**. - Compute the permutations using the
**nPr function**. - Print the result to the console using
**printf() function**. - End the program.

```
// pseudocode of nPr
1. INCLUDE stdio.h
2. FUNCTION factorial(n)
1. SET fact = 1
2. FOR i = 1 to n
1. SET fact = fact * i
3. RETURN fact
3. FUNCTION nPr(n, r)
1. SET nCr = factorial(n) / factorial(n - r)
2. RETURN nCr
4. FUNCTION main()
1. DECLARE n, r, result AS INTEGER
2. PRINT "Enter the value of n : "
3. READ n FROM USER
4. PRINT "Enter the value of r : "
5. READ r FROM USER
6. SET result = nPr(n, r)
7. PRINT "nPr = ", result
8. RETURN 0
```

🖤 0

Buy me coffee ☕

## Comments

Oops!