//Permutation
and Combinations
#include<stdio.h>
#include<conio.h>
//Declaration of three functions
//Declaration of three functions
long fact(int);
long NCR(int, int);
long NPR(int, int);
//Start of main function
//Start of main function
void main()
{
int n, r;
long
ncr, npr;
clrscr();
printf("Enter the value of n and
r\n");
scanf("%d%d",&n,&r);
if(n<r)
{
printf("Output is not possible");
}
else
{
ncr = NCR(n, r);
npr = NPR(n, r);
printf("%dC%d = %ld\n", n, r,
ncr);
printf("%dP%d = %ld\n", n, r,
npr);
}
getch();
} //End of main
//Body of 2nd function
//Body of 2nd function
long NCR(int n, int r)
{
long R;
R = fact(n)/(fact(r)*fact(n-r));
return R;
}
//Body of 3rd function
//Body of 3rd function
long NPR(int n, int r)
{
long R;
R = fact(n)/fact(n-r);
return R;
}
//Body of 1st function
//Body of 1st function
long fact(int n)
{
int i;
long R = 1;
for( i = 1 ; i <= n ; i++ )
R = R*i;
return ( R );
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.