Below is the source code for C program to find nCr and nPr using function which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
/* C program to find nCr and nPr using function */
#include <stdio.h>
long factorial(int);
long find_ncr(int, int);
long find_npr(int, int);
int main()
{
int n, r;
long ncr, npr;
printf("Enter the value of n :: ");
scanf("%d",&n);
printf("\nEnter the value of r :: ");
scanf("%d",&r);
ncr = find_ncr(n, r);
npr = find_npr(n, r);
printf("\n%dC%d = %ld\n", n, r, ncr);
printf("\n%dP%d = %ld\n", n, r, npr);
return 0;
}
long find_ncr(int n, int r) {
long result;
result = factorial(n)/(factorial(r)*factorial(n-r));
return result;
}
long find_npr(int n, int r) {
long result;
result = factorial(n)/factorial(n-r);
return result;
}
long factorial(int n) {
int c;
long result = 1;
for (c = 1; c <= n; c++)
result = result*c;
return result;
}
OUTPUT : :
/* C program to find nCr and nPr using function */
Enter the value of n :: 4
Enter the value of r :: 2
4C2 = 6
4P2 = 12
Process returned 0
Above is the source code for C program to find nCr and nPr using function which is successfully compiled and run on Windows System.The Output of the program is shown above .
Below is the source code for C program to find nCr and nPr using function which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
OUTPUT : :
Above is the source code for C program to find nCr and nPr using function which is successfully compiled and run on Windows System.The Output of the program is shown above .
need an explanation for this answer? contact us directly to get an explanation for this answer