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 = 1; i <= n; i++)
{
f=f*i;
}
return f;
}
after that you can enter n and r then run the code and see the results.
Comments
Post a Comment