Tuesday, April 6, 2021

18.18. Write a function that gets two positive integers and returns nPr (Permutation).

#include<stdio.h>
#include<conio.h>
long nPr(int n, int r)
{
long p;
int i;
for(p=1;i=r+1;i<=n;p=p*i++);
return p;
}
void main()
{
int n, r;
clrscr ();
printf ("Enter first number: ");
scanf("%d",&n):
printf ("Enter second number: ");
scanf ("&d", &r):
printf ("
nPr= %ld", nPr(n,r)); 
getch ();
}

No comments:

Post a Comment