C Program To Find The Permutation Of Two Number...

Permutation is an ordered arrangement of object. We can find in how many ways can n objects or a group of an objects can be arranged if r objects are selected at a time. This program uses factorial concept. You can refer to the following :


For example : Let we are having 9 balls. Then we can arrange 3 selected ball in P(9,3) = 504 i.e in 504 ways.
Permutation can be calculated by the formula : P(n,r) = n!/(n-r)! where n = number of available objects
and r = number of selected objects from the group



ALGORITHM:-

step 1 : start
step 2 : Input Element in array
step 3 : Set mininum element to location of zero
step 4 : Search the mininum element in the array
step 5 : Swap the value with the Min Location
step 6 : Increments Min to point of the next Element
step 7 : Repeat this process until array in sorted
step 8 : Print the Sorted Element
step 9 : Stop the Excution
PROGRAM CODE:-

#include<stdio.h>
#include<conio.h>
int fact(int);
int main()
{
    int p,r,n;
    printf(" Enter permutation numbers\n");
    printf("Enter n value : ");
    scanf("%d",&n);
    printf("\nEnter r value : ");
    scanf("%d",&r);
    p=(fact(n)/fact(n-r));     
    printf("\nFactorial is P(%d,%d) = %d",n,r,p);
    getch();
}
int fact(int c)
{
    int f=1;
    while(c>0)
    {
         f=f*c;
         c--;
    }
    return f;
}
OUTPUT:-

Enter Permutation Number for the pattern P(n,r)
Enter n value: 4

Enter r value: 3
factorial of(4,3) = 24

C Program To Implement the permutation of any number
Write a Program to Calculate the permutation