C Program To Generate Permutation And Combination | C Programming

C Program To Generate Permutation

#include <stdio.h>
long int fact(int x)
{
    long int f = 1;
    int i;
    for (i = 1; i <= x; i++)
        f = f * i;
    return (f);
}
int main()
{
    int n, r, i, p;
    printf("Enter value of n and r : ");
    scanf("%d %d", &n, &r);
    if (n >= r)
    {
        p = fact(n) / fact(n - r);
        printf("Permutation P(%d , %d) = %d", n, r, p);
    }
    else
    {
        printf("Wrong Input ! Enter n>=1 .");
    }
    return 0;
}


C Programming To Generate Combination | C Programming

#include <stdio.h>
long int fact(int x)
{
    long int f = 1;
    int i;
    for (i = 1; i <= x; i++)
        f = f * i;
    return (f);
}
int main()
{
    int n, r, i, ncr;
    printf("Enter value of n and r : ");
    scanf("%d %d", &n, &r);
    if (n >= r)
    {
        ncr = fact(n) / (fact(r) * fact(n - r));
        printf("Combination C(%d , %d) = %d", n, r, ncr);
    }
    else
    {
        printf("Wrong Input ! Enter n>=1 .");
    }
    return 0;
}

Comments

Popular posts from this blog

C Program for SCAN Disk Scheduling Algorithm | C Programming

C program to Find Cartesian Product of Two Sets | C programming

C Program To Check The String Is Valid Identifier Or Not | C Programming