Write a C program to calculate and print the value of nPr.

 #include<stdio.h>


int fact(int);

void main()
{
    int n,r,nPr;
    printf("Enter a number n\n");
    scanf("%d", &n);
    printf("Enter a number r\n");
    scanf("%d",&r);
    nPr=fact(n)/fact(n-r);
    printf("The value of %dP%d = %d\n",n,r,nPr);

}
int fact(int n)
{
    int i,f=1;
    for (int i  = 1i <= ni++)
    {
        f=f*i;
    }
    return f;   
}

after that you can enter n and r then run the code and see the results.

Comments

Popular posts from this blog

C program to find the greatest of three numbers with user input.

How to add to integers in C programming

Check whether a character Vowel or Consonant