Thursday, 16 November 2017

C program to Calculate the Value of nPr


Code:

#include   stdio.h

void main(void)
{
   printf("%d\n", fact(8));
   int n, r;
   printf("Enter value for n and r\n");
   scanf("%d%d", &n, &r);
   int npr = fact(n) / fact(n - r);
   printf("\n Permutation values is = %d", npr);
}

int fact(int x)
{
   if (x <= 1)
       return 1;
   return x * fact(x - 1);
}


Output:

40320
Enter value for n and r
5 4

Permutation values is = 120


More C Programs:











100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...