C program to find ᵑPᵣ of a number

#include< stdio.h >
#include< conio.h >
void main()
{
          int n,r,npr;
          int fact (int num);
          clrscr();
          printf("Enter the values of n and r:");
          scanf("\t%d\t %d",&n,&r);
          npr=fact(n)/fact(n-r);
          printf("nPr=%d",npr);
          getch();
}
int fact (int num)
{
         int i,a=1;
         for(i=1;i<=num;i++)
        {
                  a=a*i;
        }
        return a;
}

OUTPUT :

Enter the values of n and r:3 2
nPr =6

No comments :

Post a Comment